Lamloumi Afif
Lamloumi Afif

Reputation: 9081

Mail body with multiple line body

I'd like to send an email using C#

            SmtpClient client = new SmtpClient(_smtp, int.Parse(_port));
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.EnableSsl = bool.Parse(_enableSsl);
            client.UseDefaultCredentials = false;
            client.Credentials = new NetworkCredential(APIKey, SecretKey);
            MailMessage mail = new MailMessage();
            mail.From = _from;
            mail.To.Add(_to);
            mail.Subject = _subject;
            mail.Body = _body;
            if(Uri.IsWellFormedUriString(url, UriKind.Absolute)) mail.Body += "<br/>" + url + "<br/>" + "Cordialement";
            mail.IsBodyHtml = false;

            client.Send(mail);

The mail is sent, but its body is received as a single line .

So How can I fix this issue?

Upvotes: 0

Views: 1712

Answers (1)

user1666620
user1666620

Reputation: 4808

Since you have the following line in your code:

mail.Body += "<br/>" + url + "<br/>" + "Cordialement";

I'm going to guess that the rest of your mail.Body also contains HTML.

If you are placing HTML in the body of the MailMessage, you need to set IsBodyHtml to true - you have it set to false.

mail.IsBodyHtml = true;

Upvotes: 1

Related Questions