Bogdan Sorin
Bogdan Sorin

Reputation: 139

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

Upvotes: 2

Views: 2989

Answers (2)

Momo
Momo

Reputation: 484

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);

Upvotes: 5

musefan
musefan

Reputation: 48435

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.

Upvotes: 2

Related Questions