我正在开发一个MVC 3项目,并希望每月通过电子邮件将发票发送给客户。我将如何发送这些多封电子邮件,如果是循环,我将如何编写此循环?
这是我的InvoiceMailer代码:
public virtual MailMessage InvoiceMailed()
{
var invoices = db.Invoice.FirstOrDefault();
var client = db.Clients.FirstOrDefault();
var mailMessage = new MailMessage{Subject = "InvoiceMailed"};
mailMessage.To.Add("amecily@gmail.com");
mailMessage.Bcc.Add(client.EmailAddress);
ViewBag.Name = client.FullName;
ViewBag.Number = invoices.InvoiceNumberID;
ViewBag.Amount = invoices.InvoiceAmount;
ViewBag.Month = invoices.InvoiceMonth;
PopulateBody(mailMessage, viewName: "InvoiceMailed");
return mailMessage;
}
我的电子邮件的视图:
Hello @ViewBag.Name
<br /><br />
This is your invoice from DFP Productions for the month of @ViewBag.Month
<br /><br />
@ViewBag.Number<br />
@ViewBag.Amount<br />
@ViewBag.Month<br />
电子邮件目前正在发送,但显然只有一组信息,只发送给三个收件人中的两个(这是由于FirstOrDefault,我应该使用什么?)。
谢谢, 艾米
答案 0 :(得分:0)
基本逻辑是