Is is best practice to send both HTML and Text email?
If I only send HTML what are the dangers?
I'm thinking something like this below from
// Assign a sender, recipient and subject to new mail message
MailAddress sender =
new MailAddress("email@example.com", "Sender");
MailAddress recipient =
new MailAddress("firstname.lastname@example.org", "Recipient");
MailMessage m = new MailMessage(sender, recipient);
m.Subject = "Test Message";
// Define the plain text alternate view and add to message
string plainTextBody =
"You must use an email client that supports HTML messages";
AlternateView plainTextView =
plainTextBody, null, MediaTypeNames.Text.Plain);
// Define the html alternate view with embedded image and
// add to message. To reference images attached as linked
// resources from your HTML message body, use "cid:contentID"
// in the <img> tag...
string htmlBody =
AlternateView htmlView =
htmlBody, null, MediaTypeNames.Text.Html);
// ...and then define the actual LinkedResource matching the
// ContentID property as found in the image tag. In this case,
// the HTML message includes the tag
// <img src=\"cid:SampleImage\"> and the following
// LinkedResource.ContentId is set to "SampleImage"
LinkedResource sampleImage =
sampleImage.ContentId = "SampleImage";
// Finally, configure smtp or alternatively use the
// system.net mailSettings
SmtpClient smtp = new SmtpClient
Host = "smtp.example.com",
UseDefaultCredentials = false,
new NetworkCredential("username", "password")
// <smtp deliveryMethod="Network">
// <network host="smtp.example.com"
// port="25" defaultCredentials="true"/>
ArgumentException("Undefined sender and/or recipient.");
FormatException("Invalid sender and/or recipient.");
InvalidOperationException("Undefined SMTP server.");
throw new SmtpFailedRecipientException(
"The mail server says that there is no mailbox for recipient");
catch (SmtpException ex)
// Invalid hostnames result in a WebException InnerException that
// provides a more descriptive error, so get the base exception
Exception inner = ex.GetBaseException();
throw new SmtpException("Could not send message: " + inner.Message);
I would say that, in today's world, the "best-practice" approach would be to ensure that you send your message as both plain text and HTML (if you really want to send HTML email messages).
Oh, and make sure you do actually send the content in the plain text view, rather than a single sentence saying "You must use an email client that supports HTML messages". Google Mail takes this approach, and it seems to work perfectly, allowing "rich" views on full-fledged PC clients, whilst also allowing "minimal" views on more restricted devices (i.e. Mobile/Cell phones).
If you want to take a purist's view, you wouldn't be sending HTML emails at all, nor would you ever "attach" a binary file to an email. Both corruptions of the original email standard, which was only ever originally intended for plain text. (See some people's opinions of this here and here)
However, in the pragmatic modern-day real world, HTML email is very real, and very acceptable. The primary downside to sending HTML email is whether the recipient will see the email in the way that you intended them to see it. This is much the same problem that web designers have battled with for years; getting their websites to look "just right" in all possible browsers (although it's significantly easier today than it was many years ago).