471,334 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,334 software developers and data experts.

Carriage returns in MailMessage object

Ant
Hi,
I'm using the MailMessage object to send an email programmatically via a
console application. It needs to have lines breaks. For example:

string s = "This is the first line + "\n\r" + "and this is the second line.";

This works fine when written to the console however the MailMessage object
ignores the \ escape key and returns a single lined string.

How can I use carriage returns in a MailMessage?

Many thanks in advance.

Dec 20 '05 #1
4 1738
try Environment.NewLine?

"Ant" <An*@discussions.microsoft.com> wrote in message
news:2F**********************************@microsof t.com...
Hi,
I'm using the MailMessage object to send an email programmatically via a
console application. It needs to have lines breaks. For example:

string s = "This is the first line + "\n\r" + "and this is the second
line.";

This works fine when written to the console however the MailMessage object
ignores the \ escape key and returns a single lined string.

How can I use carriage returns in a MailMessage?

Many thanks in advance.

Dec 20 '05 #2
Please use "\r\n" or Environment.NewLine

--
Vince

Dec 20 '05 #3
Ant
Hi,

well, I tried both your solutions. "\r\n" gives the same result as "\n\r"
and Enviroment.NewLine, is also treated the same. I'm guessing that because
the email is HTML, it needs a <BR>. Does anybody know how I can send a <BR>
in a string?

Many thanks for your thoughts on this

Ant

"John Richardson" wrote:
try Environment.NewLine?

"Ant" <An*@discussions.microsoft.com> wrote in message
news:2F**********************************@microsof t.com...
Hi,
I'm using the MailMessage object to send an email programmatically via a
console application. It needs to have lines breaks. For example:

string s = "This is the first line + "\n\r" + "and this is the second
line.";

This works fine when written to the console however the MailMessage object
ignores the \ escape key and returns a single lined string.

How can I use carriage returns in a MailMessage?

Many thanks in advance.


Dec 21 '05 #4
Ant
Actually, I inadvertently answered my own question. Because it is treating
the text as HTML, I simply added the break to the string i.e.

"This is the text<BR>This is the next line."

and it wote it to the email with the breaks.
"Ant" wrote:
Hi,

well, I tried both your solutions. "\r\n" gives the same result as "\n\r"
and Enviroment.NewLine, is also treated the same. I'm guessing that because
the email is HTML, it needs a <BR>. Does anybody know how I can send a <BR>
in a string?

Many thanks for your thoughts on this

Ant

"John Richardson" wrote:
try Environment.NewLine?

"Ant" <An*@discussions.microsoft.com> wrote in message
news:2F**********************************@microsof t.com...
Hi,
I'm using the MailMessage object to send an email programmatically via a
console application. It needs to have lines breaks. For example:

string s = "This is the first line + "\n\r" + "and this is the second
line.";

This works fine when written to the console however the MailMessage object
ignores the \ escape key and returns a single lined string.

How can I use carriage returns in a MailMessage?

Many thanks in advance.


Dec 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Matt Mercer | last post: by
7 posts views Thread by mattrapoport | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.