전자 메일 설정 클래스를 통해 전자 메일 본문에있는 항목 목록을 채우려고합니다. 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
@ 62071072 : 추가 서식이 적용됩니다. 당신이 접근하는 방식은 이메일이 HTML인지 아닌지에 달려 있습니다. 귀하의 코드에 HTML이 표시되지 않으므로 나는 추측하고 있습니다. 그러나 우선,'messager.Body + = item + Environment.NewLine;과 같은 간단한 것을 시도해 볼 수 있습니다. – David