Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - Send HTML email with line breaks

Tags:

c#

email

I'm attempting to send emails from my C# app using the System.Net.Mail.MailMessage class. For the body of the email, I want to include line breaks to create separate blocks of text. How can I get an email client, like Outlook, to respect the line breaks when display the email has HTML to users? What character(s) do I insert in the body of the email text so that the line breaks are treated as line breaks?

Note: The body of my email is pure text, not HTML.

like image 600
Hosea146 Avatar asked Aug 09 '11 16:08

Hosea146


2 Answers

Line breaks are white space characters, and all white space characters are interpreted as spaces in HTML.

You can use break tags (<br/>) to add line breaks in the HTML code, and you can use paragraph tags (<p>...</p>) around paragraphs to get a distance between them.

like image 106
Guffa Avatar answered Sep 23 '22 20:09

Guffa


You can just use Environment.NewLine property. That will insert a newline string defined for the current environment.

like image 39
sithius92 Avatar answered Sep 22 '22 20:09

sithius92