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?