Hello,
I m trying to send HTML content via Gmail bu couldn't manage. Here is my sample code. Hope you can help me.
C#
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 = " Happy Birthday 2 U "; 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); } } } }
Rajeesh MenothRank #118 · 18.4K reputationPosted Nov 16, 2015, 12:00 AM EST