我正在尝试通过我的 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);
}
}
}