views:

40

answers:

6

Hi Guys, I am sending mail to the customers. And the format is like this:

Name: abc. Company:ccc. Address: sde.

So the mail is coming out in continuous format which I don't want.

I want it in this format:

Name: abc.

Company:ccc.

Address: sde.

I'm currently using string.format to populate each of the values and later on replacing '.' with '\n'.
However, it looks like that is not working. Any suggestions on how to make it look like this?

A: 

Have you tried "\n\r"?

Is the body set to be plain text or html?

BigBlondeViking
the body is set to HTML
alice7
+3  A: 

Try Environment.NewLine

Scrappydog
I tried replacing char . with environemnt.newline and it gave me error.
alice7
+4  A: 

Use BodyFormat property to format your mails as HTML format, and use <br /> for the line breaks.

MailMessage myMail = new MailMessage();
myMail.BodyFormat = MailFormat.Html;
myMail.Body = "Name: abc.<br />";
myMail.Body += "Company:ccc.<br />";
myMail.Body += "Address: sde.<br />";
Canavar
A: 

If you are building a long string, I recommend you use StringBuilder.

StringBuilder sb = new StringBuilder();
sb.AppendLine(string1);
sb.AppendLine(string2):
sb.AppendLine(""); //empty line
mailMessage.Body = sb.ToString();

Edit: I use this to send our text only emails and it works on non-HTML emails.

Russell Steen
A: 

@Canavar's answer is good, but not all mail clients support html and even those that do may have it turned off for security purposes.

As an alternative, I would say use MailFormat.Text and use the System.Environment.NewLine

David Stratton
A: 

If HTML format is ok, you could just insert

<br>

If not, and you are using outlook to view the message, try one of these two:

  1. Use \n\n
  2. Keep your period so that the line ends with .\n

I know this seems odd, but it may make outlook happy.

Matt Wrock