Naive
Naive

Reputation: 395

How Can I Add New Line In Email Body?

I am Sending Mail to Specific User, in mail.body after my message I wanted to Add Few more details which will be in new line, I tried br,n, Environment.NewLine but nothing seems to be working, is there a way which I can try.

Thank you In Advance.

 protected void SendMail()
    {


        MailMessage mail = new MailMessage();

        mail.From = new MailAddress("xyz");
        mail.To.Add("abc");
        mail.Subject = "INCOMPLETE APPLICATION CASE ID [CASE ID]";
        mail.IsBodyHtml = true;
        mail.Body = "Your Incomplete Grade Application has been Result[]";

        System.Net.Mail.Attachment attachment;
        attachment = new System.Net.Mail.Attachment(Server.MapPath("files/CS00022904.pdf"));
        mail.Attachments.Add(attachment);
        var smtp = new System.Net.Mail.SmtpClient();
        {
            smtp.Host = "10.12.46.3";
            smtp.Port = 25;
            smtp.EnableSsl = false;
            smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            smtp.Credentials = new NetworkCredential("", "");

        }
        smtp.Send(mail);
    }

Upvotes: 2

Views: 10848

Answers (3)

T.S.
T.S.

Reputation: 19340

There are few ways, one of these:

var sb = new StringBuilder();
sb.Append("Line 1").Append("<br />");
. . . . . 
sb.Append("Line N").Append("<br />");
// Sometimes later
mail.Body = sb.ToString();

Advantage of string builder is that you can efficiently add lines in loop and in differed way. you can pass it to different methods and keep adding lines, and use it in the end. This is also helpful if your text stored as lines and you can iterated them.

Upvotes: 2

Fabio
Fabio

Reputation: 71

Since the BodyFormat is set to HTML, you can just add <br /> to the body string.

Upvotes: 0

JBdev
JBdev

Reputation: 363

You should be able to use br:

mail.Body = "Your Incomplete Grade Application has been Result[] <br /> Here is another line of text!";

Upvotes: 4

Related Questions