Jump to content

To get Line Break in Mail Body


dhanjish

Recommended Posts

hello,I want to send some data in mail with Line breaksam getting the data from the database into a variable, where new line entries are stored as spaces.while retrieving from database i am using Regex object to replace '\n' with "<br>"I am able to get this result into asp Datgrid.But while sending in same way to mail, its showing data as single para.Please let me know if theres any solution to my problem.Looking forward for a quick response,Romita

Link to comment
Share on other sites

If you are sending the email in HTML format, then the <br />s should work just fine. If, on the other hand, you are sending the email in plain-text format, you'll need to keep the "\n"s.plain-text:

string emailBody = "This is a sample.\n\nThis line has two line breaks above it.\nDone.";

HTML

string emailBody = "This is a sample.<br /><br />This line has two line breaks above it.<br />Done.";

If you are using the System.Net.Mail.MailMessage class to send the email, you can tell it whether to send as plain-text or HTML by using the .IsBodyHtml property:

MailMessage message = new MailMessage(fromAddress, toAddress);message.Subject = "Subject";message.Body = emailBody;message.IsHtmlBody = true; // or false, depending...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...