I need to send a list of tasks to users in my MVC application.
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
Currently I am doing like this. But its not formatted. What I need is to an object with the list of tasks to the email tempalate.