G
Guest
I wrote some code to send an email with two alternate views:
1) html
2) plain text
All the html enabled email clients accept the html just fine and disregard
the plain text version.
However, the plain-text-only email clients I've tried keep reading my plain
text email and formatting it in all kinds of crazy ways.
I tried sending the plain text version to an html enabled email client and
it read my plain text and it looked great!
I've tried dozens of ways. Here's my latest. It sends email just fine. But,
it's not telling the email clients what they need to know. Help!
VB 2005
Dim mailFrom As MailAddress = Nothing
Dim mailTo As MailAddress = Nothing
Dim smtpClient As SmtpClient = Nothing
Dim altViewHTML As AlternateView = Nothing
Try
mailFrom = New MailAddress("(e-mail address removed)")
mailTo = New MailAddress(txtTestData.Text.ToString())
altViewHTML = Net.Mail.AlternateView.CreateAlternateViewFromString("<b>this
will be bold in html</b>", System.Text.Encoding.UTF8,
MediaTypeNames.Text.Html)
Using mailMessage As New MailMessage(mailFrom, mailTo)
smtpClient = New SmtpClient("mail.joesdiner.com")
mailMessage.Subject = "test from joes diner"
mailMessage.BodyEncoding = System.Text.Encoding.ASCII
mailMessage.Body = "this is a test from joes diner"
altViewHTML.TransferEncoding = Net.Mime.TransferEncoding.QuotedPrintable
mailMessage.AlternateViews.Add(altViewHTML)
smtpClient.Send(mailMessage)
End Using
Catch ex As Exception
'handle error
Finally
If Not IsNothing(mailFrom) Then mailFrom = Nothing
If Not IsNothing(mailTo) Then mailTo = Nothing
If Not IsNothing(altViewHTML) Then altViewHTML = Nothing
If Not IsNothing(smtpClient) Then smtpClient = Nothing
End Try
1) html
2) plain text
All the html enabled email clients accept the html just fine and disregard
the plain text version.
However, the plain-text-only email clients I've tried keep reading my plain
text email and formatting it in all kinds of crazy ways.
I tried sending the plain text version to an html enabled email client and
it read my plain text and it looked great!
I've tried dozens of ways. Here's my latest. It sends email just fine. But,
it's not telling the email clients what they need to know. Help!
VB 2005
Dim mailFrom As MailAddress = Nothing
Dim mailTo As MailAddress = Nothing
Dim smtpClient As SmtpClient = Nothing
Dim altViewHTML As AlternateView = Nothing
Try
mailFrom = New MailAddress("(e-mail address removed)")
mailTo = New MailAddress(txtTestData.Text.ToString())
altViewHTML = Net.Mail.AlternateView.CreateAlternateViewFromString("<b>this
will be bold in html</b>", System.Text.Encoding.UTF8,
MediaTypeNames.Text.Html)
Using mailMessage As New MailMessage(mailFrom, mailTo)
smtpClient = New SmtpClient("mail.joesdiner.com")
mailMessage.Subject = "test from joes diner"
mailMessage.BodyEncoding = System.Text.Encoding.ASCII
mailMessage.Body = "this is a test from joes diner"
altViewHTML.TransferEncoding = Net.Mime.TransferEncoding.QuotedPrintable
mailMessage.AlternateViews.Add(altViewHTML)
smtpClient.Send(mailMessage)
End Using
Catch ex As Exception
'handle error
Finally
If Not IsNothing(mailFrom) Then mailFrom = Nothing
If Not IsNothing(mailTo) Then mailTo = Nothing
If Not IsNothing(altViewHTML) Then altViewHTML = Nothing
If Not IsNothing(smtpClient) Then smtpClient = Nothing
End Try