简体   繁体   中英

Append a new line in a Outlook mailitem html body

I need some help formatting text in a mail item html body. I want to add more messages in the mail body but on all messages on different lines. It may be obviously easy but idk I have a lapsus or something.

Format I want:

-Message.
-Message.
-Message.

Format I get now:

Message,Message,Message.

Code:

StringBuilder infoMessage = new StringBuilder();
foreach (string element in form.InfoMessages)
{
infoMessage.AppendLine(element);
}
mailItem2.HTMLBody = infoMessage;

InfoMessages is a List<string>

Edited for a better understanding

It's a HTML body so just use HTML tags:

StringBuilder infoMessage = new StringBuilder();
foreach (string element in form.InfoMessages)
{
    infoMessage.AppendLine("<p>" + element + "</p><br/>");
}
mailItem2.HTMLBody = string.Format("{0} <br/> {1}",infoMessage,mailItem2.HTMLBody);

HTML should use <br/> for new lines, not \\n (which would apply to the plain text body).

Try this change instead:

StringBuilder infoMessage = new StringBuilder();
foreach (string element in form.InfoMessages)
{
    infoMessage.AppendLine(element + "<br/>");
}

mailItem2.HTMLBody = string.Format("{0} <br/>{1}",infoMessage,mailItem2.HTMLBody);

Disclaimer: <br/> isn't the only way to separate elements on to new lines, but it seems most applicable in this instance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM