我需要在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)
{
}
}
@{
Layout = null;
}
To: @ViewBag.To
From: @ViewBag.From
Subject: @ViewBag.Subject
<h3>Pending Tasks</h3>
@ViewBag.Content
目前我这样做。但它没有格式化。我需要的是一个带有电子邮件tempalate任务列表的对象。