Ich versuche, die Liste der Elemente in meinem E-Mail-Textkörper über meine emial-Setup-Klasse aufzufüllen. Wenn ich versuche, E-Mail in meinem Outlook zu öffnen, sehe ich nur ein Element, wo ich eine Liste von Elementen erwarte.Liste der Elemente in E-Mail-Nachrichtentext ausfüllen
Unten ist mein Code:
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);
}
}
}
Danke für die Antwort und danke für Korrigieren meines Codes. Ich bin in der Lage, Liste der Elemente zu füllen, aber alle kommen in nur einer Zeile. – 62071072SP
@ 62071072: Hier kommt zusätzliche Formatierung ins Spiel. Wie Sie damit umgehen, hängt davon ab, ob Ihre E-Mail HTML ist oder nicht. Ich sehe HTML nicht in Ihrem Code, also nehme ich nicht an. Aber Sie können versuchen, für den Anfang etwas so einfaches wie: 'messager.Body + = Element + Environment.NewLine;' – David