MVC邮件电子邮件发送带有列表的对象?

时间:2016-10-05 14:12:51

标签: asp.net-mvc postal

我需要在MVC应用程序中向用户发送任务列表。

 public static void Send()
    {
        try
        {
            StringBuilder sb = new StringBuilder();

            UserRepository userRepo = new UserRepository();
            var users = userRepo.GetUsers();

            TaskRepository repo = new TaskRepository();

            foreach (var rec in users)
            {
                var tasks = repo.GetTasksOfUser(rec.UserID);

                sb.AppendLine("Task Name                              Due Date");
                sb.AppendLine("---------                              --------");

                foreach (var results in tasks)
                {
                    sb.AppendLine(results.TaskName.PadRight(30, ' ') + "          " + String.Format("{0:MM/dd/yyyy HH:mm tt}", results.DueDate));
                }

                dynamic email = new Email("TaskEmail");
                email.To = rec.Email;
                email.From = "no-reply@xyz.com";
                email.Subject = "Pending Tasks";
                email.Content = sb.ToString();
                email.Send();
            }
        }
        catch (Exception ex)
        {

        }
    }

TaskEmail.cshtml

 @{
    Layout = null;
}

To: @ViewBag.To
From: @ViewBag.From
Subject: @ViewBag.Subject

<h3>Pending Tasks</h3>

@ViewBag.Content

目前我这样做。但它没有格式化。我需要的是一个带有电子邮件tempalate任务列表的对象。

0 个答案:

没有答案