Raysefo

Raysefo

  • 1.4k
  • 284
  • 150.9k

Send HTML E-mail via Gmail?

Nov 15 2015 11:36 AM
Hello,
 
I m trying to send HTML content via Gmail bu couldn't manage. Here is my sample code. Hope you can help me.
 
 
var fromAddress = new MailAddress("[email protected]", "Cenk The Great");             var toAddress = new MailAddress("[email protected]", "Bir Dost");             const string fromPassword = "pass";             const string subject = "TEST";             var body = "<html>< head >< title > Happy Birthday 2 U </ title >< meta http - equiv = \"Content-Type\" content = \"text/html; charset=utf-8\" ></ head >< body bgcolor = \"#FFFFFF\" leftmargin = \"0\" topmargin = \"0\" marginwidth = \"0\" marginheight = \"0\" >< table id = \"Table_01\" width = \"600\" height = \"452\" border = \"0\" cellpadding = \"0\" cellspacing = \"0\" >< tr > < td colspan = \"3\" > < img src = \"C:\\Users\\197199\\Desktop\\dogum günü yeni\\DG_01.jpg\" width = \"600\" height = \"84\" alt = \"\" ></ td ></ tr > < tr >< td rowspan = \"2\" >< img src = \"C:\\Users\\197199\\Desktop\\dogum günü yeni\\DG_02.jpg\" width = \"37\" height = \"368\" alt = \"\" ></ td >< td >< img src = \"C:\\Users\\197199\\Desktop\\dogum günü yeni\\DG_03.jpg\" width = \"307\" height = \"61\" alt = \"\" ></ td >< td rowspan = \"2\" > < img src = \"C:\\Users\\197199\\Desktop\\dogum günü yeni\\DG_04.jpg\" width = \"256\" height = \"368\" alt = \"\" ></ td ></ tr >< tr >< td > < img src = \"C:\\Users\\197199\\Desktop\\dogum günü yeni\\DG_05.jpg\" width = \"307\" height = \"307\" alt = \"\" ></ td > </ tr ></ table ></ body ></ html > ";                 using (               var smtp = new SmtpClient             {                 Host = "smtp.gmail.com",                 Port = 587,                 EnableSsl = true,                 DeliveryMethod = SmtpDeliveryMethod.Network,                 UseDefaultCredentials = false,                 Credentials = new NetworkCredential(fromAddress.Address, fromPassword)             })             {                 var mimeType = new System.Net.Mime.ContentType("text/html");                 var alternate = AlternateView.CreateAlternateViewFromString(body, null, MediaTypeNames.Text.Html);                 {                     using (var message = new MailMessage(fromAddress, toAddress)                     {                         Subject = subject,                         IsBodyHtml = true                       })                     {                         message.AlternateViews.Add(alternate);                         smtp.Send(message);                     }                 }             }         }

Answers (1)