Net.Mail.MailMessage.AlternateViews problem sending html and text

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
 
J

Jack Jackson

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! :)

If a plain text mail client is not aware of MIME types, it will
display the entire e-mail message. Perhaps the text-only clients you
have tried don't know how to show only the plain text part of the
message.
 
G

Guest

Yes, I thought the same thing! :)

Then, I saw an email from iTunes that did what I wanted and it displayed
correctly in the text email client. So, I'm wondering what trick they used.

Any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top