我想通過我的emial安裝程序類在我的電子郵件正文中填充項目列表。 當我試圖在我的Outlook中打開電子郵件時,我可以看到只看到一個項目,我期待的項目列表。填充電子郵件正文中的項目列表
下面是我的代碼:
public class EmailSetup
{
string toEmailSetup = string.Empty;
string fromEmailSetup = string.Empty;
string domainName = string.Empty;
string emailServer = string.Empty;
public void ApplicationFailedEmailSetup(List<string>ApplicationsInactive,DateTime dateRun)
{
toEmailSetup = ConfigurationManager.AppSettings["To mailid"];
fromEmailSetup = ConfigurationManager.AppSettings["From mailid"];
domainName = ConfigurationManager.AppSettings["Domain Name"];
emailServer = ConfigurationManager.AppSettings["Email Server"];
try
{
var messager = new MailMessage();
messager.To.Add(toEmailSetup);
messager.Subject = "Applications Crashed/Closed";
messager.From = new MailAddress(fromEmailSetup);
try
{
messager.Body = "Following applications you are monitoring are closed are crashed:";
**foreach (var item in ApplicationsInactive)
{
messager.Body = item;
}** // Here i am trying to populate list of applications.
}
catch (Exception)
{
throw;
}
var smtp = new SmtpClient(emailServer);
smtp.EnableSsl = true;
try
{
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Send(messager);
}
catch (Exception)
{
throw;
}
}
catch (SmtpException ex)
{
throw new ApplicationException
("SmtpException has occured: " + ex.Message);
}
}
}
感謝您的答覆和感謝糾正我的代碼。我可以填充項目列表,但所有內容都只有一行。 – 62071072SP 2012-04-10 14:11:09
@ 62071072:這是附加格式化的地方。你的方法取決於你的電子郵件是否(或者應該是)HTML。我在代碼中看不到HTML,所以我假設不是。但對於初學者,你可以嘗試一些簡單的事情:'messager.Body + = item + Environment.NewLine;' – David 2012-04-10 14:17:53