Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am creating email client application in windows forms. For sending mail, 
i am using Yarte control. When i am sending email, I am able to send the email but in my gmail inbox i am getting Output of mail is RAW HTML.

For example- i am getting output like this.
<pre>
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META content="text/html; charset=unicode" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.7601.17514"></HEAD>
<BODY>
<DIV dir=ltr>
<DIV>Hello <BR></DIV>




In above HTML, my output is only "Hello" but its adding some extra raw html.

Please help.

What I have tried:

i am using Yarte control. When i am sending email, I am able to send the email but in my gmail inbox i am getting Output of mail is RAW HTML.

                MailMessage mail = new MailMessage();
               SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

                mail.From = new MailAddress(mailFrom);
                string mailAddresses = richtxtTo.Text;
                if(string.IsNullOrEmpty(mailAddresses))
                {
                    MessageBox.Show("Please specify atleast one recipient!");
                    return;
                }
                // This loop is used to send to multiple receiptents
                foreach (var address in mailAddresses.Split(new[] { ";" },       tringSplitOptions.RemoveEmptyEntries))
                {
                    mail.To.Add(mailAddresses);
                }
                //mail.To.Add(richtxtTo.Text);
                mail.Subject = mailSubject;
                mail.Body = htmlEditor1.Html;
                SmtpServer.Port = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential(mailTo, "Password");
                SmtpServer.EnableSsl = true;
                SmtpServer.Send(mail);
                MessageBox.Show("Mail Sent");
                htmlEditor1.Html = "";
                richtxtTo.Text = "";
                btnForward.Visible = true;
                btnReply.Visible = true;
Posted
Updated 20-Feb-17 21:36pm
v2

1 solution

Hi,

add mail.IsBodyHtml = true; prior to sending an email.
 
Share this answer
 
v2
Comments
Adityakumar2318 21-Feb-17 4:55am    
@jimmson Thanks alot. Now it works fantastic. I accepted your solution.
jimmson 21-Feb-17 4:56am    
You're welcome.
Karthik_Mahalingam 21-Feb-17 8:12am    
5
jimmson 21-Feb-17 8:18am    
Thank you!

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