Click here to Skip to main content
15,888,253 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Cant figure it out.

I have a MailMessage msg.

I am trying to send email by using EmailClient.Send(msg). I't working but, in email body I nave a several new lines (\n) and they are not transferred to my email message. Instead of normal email, I am getting a single line with text, and also without \n - they are simply disappeared.

How can I prevent this thing and get a normal email with new lines?
Posted
Comments
[no name] 26-May-14 7:41am    
Sounds to me that you have your email set to use HTML. Switch to normal text or replace the newlines with <BR>
Member 10503105 26-May-14 8:12am    
Thanks)
V. 26-May-14 7:48am    
also use \n\r instead of just \n

1 solution

using System.Net;
using System.Net.Mail;
using System.Net.Mime;

        private void button1_Click(object sender, EventArgs e)
        {
            SmtpClient Smtp = new SmtpClient("smtp.gmail.com", 587); //SMTP server and port number
            Smtp.Credentials = new NetworkCredential("yourmail@gmail.com", "password");
            Smtp.EnableSsl = true;
            MailMessage Message = new MailMessage();
            Message.From = new MailAddress("yourmail@gmail.com", "Sender Name", Encoding.UTF8);
            Message.To.Add(new MailAddress("abc@abc.com"));
            Message.Subject = "New Message";
            Message.SubjectEncoding = Encoding.UTF8;
            Message.Body = "Message text\n123\n456\n789";
            Smtp.Send(Message);
        }


The result:

Message text
123
456
789

 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900