我正在发送邮件给特定用户,在mail.body中我的消息之后我想添加更多细节将在新行中,我尝试了 br,n,Environment.NewLine 但没有似乎有效,有没有办法让我尝试。
先谢谢你。
protected void SendMail()
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress("xyz");
mail.To.Add("abc");
mail.Subject = "INCOMPLETE APPLICATION CASE ID [CASE ID]";
mail.IsBodyHtml = true;
mail.Body = "Your Incomplete Grade Application has been Result[]";
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment(Server.MapPath("files/CS00022904.pdf"));
mail.Attachments.Add(attachment);
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "10.12.46.3";
smtp.Port = 25;
smtp.EnableSsl = false;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential("", "");
}
smtp.Send(mail);
}
答案 0 :(得分:1)
有几种方法,其中之一:
var sb = new StringBuilder();
sb.AppendLine("Line 1");
. . . . .
sb.AppendLine("Line N");
// Sometimes later
mail.Body = sb.ToString();
字符串构建器的优点是您可以以不同的方式有效地在循环中添加行。您可以将它传递给不同的方法并继续添加行,并最终使用它。
答案 1 :(得分:0)
你应该可以使用br:
mail.Body = "Your Incomplete Grade Application has been Result[] <br /> Here is another line of text!";
答案 2 :(得分:0)
由于BodyFormat设置为HTML,您只需添加&lt; br /&gt;到身体的字符串。