c# - Send Mail in HTML Format using mvc -


i need send mail in html format. googled lot not able expected result html format. can missing in following code 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                     };   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;                 mail.subject = "password credentials";   smtp.send(mail.from, mail.to, mail.subject, msg.body);  

output

enter image description here

not working example, hint given below:

var msg = new mailmessage();

var htmlbody = alternateview.createalternateviewfromstring(your_html_string_in_variable, encoding.utf8,"text/html");

msg.alternateviews.add(htmlbody);

isbodyhtml = true;

... , rest of stuff


Comments