How to include HTML content in SMTP email messages to Gmail recipients

I’m working with C# .NET 3.5 and trying to send emails with HTML formatting to Gmail addresses. My current setup uses MailMessage and SmtpClient classes, but I’m having trouble getting the HTML content to render properly in the email body.

I want to include formatted HTML elements like clickable links where the display text differs from the actual URL. Right now my emails are not showing the HTML formatting correctly.

Here’s what I’m currently trying:

MailMessage email = new MailMessage("[email protected]", recipientAddress, "Email Subject", "<html><body><a href='https://www.example.com'>Click Here</a></body></html>");
NetworkCredential credentials = new NetworkCredential("[email protected]", "password123");
email.IsBodyHtml = true;

SmtpClient mailClient = new SmtpClient("smtp.gmail.com");
mailClient.UseDefaultCredentials = false;
mailClient.EnableSsl = true;
mailClient.Credentials = credentials;
mailClient.Port = 587;

mailClient.Send(email);

What am I missing to make the HTML render correctly in Gmail?

Gmail’s HTML rendering is a pain because of how it handles HTML and CSS. I’ve dealt with this before. You need simple HTML - no complex structures or external styles since Gmail strips them out. Stick to inline styles and use tables for layout instead of modern HTML elements. Make sure you set ContentType properly too. Just using IsBodyHtml often isn’t enough. Try creating an AlternateView for your HTML content and explicitly define the MediaType - this usually fixes Gmail compatibility issues. Also check that your HTML isn’t getting encoded during sending, which breaks rendering.