Click here to Skip to main content
16,012,468 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I need to send the mail in HTML Format. I googled lot but i could not able to get the expected result as html format. Can anyone help what i am missing in this following code to get the html format mail.

C# Code :-
--------

MailAddress sender = new MailAddress(ConfigurationManager.AppSettings["smtpUser"]);
string MailId = Convert.ToString(Session["EmailID"]);

SmtpClient smtp = new SmtpClient()
{
Host = ConfigurationManager.AppSettings["smtpServer"],
Port = Convert.ToInt32(ConfigurationManager.AppSettings["smtpPort"]),
UseDefaultCredentials = false,
EnableSsl = true,
Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["smtpUser"], ConfigurationManager.AppSettings["smtpPass"]),
DeliveryMethod = SmtpDeliveryMethod.Network
};
XML
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
              string text = "<table><tr><td>EmpId</td><td>Emp name</td><td>age</td></tr><tr><td>value</td><td>value</td><td>value</td></tr></table>";
              msg.From = sender;
              msg.To.Add(MailId);
              msg.Body = text;
              msg.IsBodyHtml = true;

smtp.Send(mail.From, mail.To, mail.Subject, msg.Body);
Posted
Comments
Sergey Alexandrovich Kryukov 8-May-15 3:12am    
What's the problem?
—SA
dineshkanagaraj 8-May-15 3:35am    
I am getting the text format of result instead of html format result

1 solution

I think you should use
C#
smtp.Send(msg);

instead of
C#
smtp.Send(mail.From, mail.To, mail.Subject, msg.Body); 
 
Share this answer
 
Comments
dineshkanagaraj 8-May-15 4:04am    
Thank you very much... I have spend one and half hours to clear this issues... Have a nice day :)

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