Discussion:
Net.Mail.MailMessage.AlternateViews problem sending html and text
(too old to reply)
Captain Dave!
2007-08-17 03:50:01 UTC
Permalink
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("***@joesdiner.com")
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
Ralph
2007-08-17 05:49:51 UTC
Permalink
"Captain Dave!" <***@hawaiianair.com> wrote in message news:57648384-C6E5-4663-85EF-***@microsoft.com...
<snipped>
Post by Captain Dave!
VB 2005
You're in the wrong newsgroup. This newsgroup is for classic VB (VB6 and
lower).

You can find complete list of managed (dotNet) newsgroups here:
http://msdn.microsoft.com/subscriptions/managednewsgroups/list.aspx
Captain Dave!
2007-08-17 19:30:02 UTC
Permalink
Thanks, Ralph! :-)

Newsgroup newbie mistake.
Post by Ralph
<snipped>
Post by Captain Dave!
VB 2005
You're in the wrong newsgroup. This newsgroup is for classic VB (VB6 and
lower).
http://msdn.microsoft.com/subscriptions/managednewsgroups/list.aspx
Loading...