Home All Groups Group Topic Archive Search About

MailMessage to send email with both Text and HTML versions...

Author
29 Apr 2006 10:36 AM
Stu Lock
Hi,

I have an app that has beenusing the JMail COM component to generate emails.
I would like to switch to the using the  .Net 2.0 MailMessage object
instead - as it is more portable.

The jmail component allowed me to set both an HTML body and a text body -
this meant that if a users' email client didn't support html - the user
would see the text only version with an html attachment. The MailMessage
object only appears to have one Body setting and you have to switch it
between IsHtml or not.

Is there any way of sending both text and html versions in one email as
jmail does - but using interval .Net objects?

Thanks in advance,

Stu

Dim oSmtp As New SmtpClient
oSmtp.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory
oSmtp.PickupDirectoryLocation = "c:\Pickup\"
oSmtp.UseDefaultCredentials = True
Dim oMsg As New MailMessage()
oMsg.From = New MailAddress(myfromn***@domain.com)
oMsg.To.Add(New MailAddress***@domain.com)
oMsg.Subject = "My Subject..."
oMsg.IsBodyHtml = True
oMsg.Body = "My HTML...blah..."
oSmtp.Send(oMsg)

Author
29 Apr 2006 4:03 PM
Chris Chilvers
Show quote Hide quote
On Sat, 29 Apr 2006 11:36:31 +0100, "Stu Lock" <s.l***@cergis.com>
wrote:

>Hi,
>
>I have an app that has beenusing the JMail COM component to generate emails.
>I would like to switch to the using the  .Net 2.0 MailMessage object
>instead - as it is more portable.
>
>The jmail component allowed me to set both an HTML body and a text body -
>this meant that if a users' email client didn't support html - the user
>would see the text only version with an html attachment. The MailMessage
>object only appears to have one Body setting and you have to switch it
>between IsHtml or not.
>
>Is there any way of sending both text and html versions in one email as
>jmail does - but using interval .Net objects?
>
>Thanks in advance,
>
>Stu
>
>Dim oSmtp As New SmtpClient
>oSmtp.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory
>oSmtp.PickupDirectoryLocation = "c:\Pickup\"
>oSmtp.UseDefaultCredentials = True
>Dim oMsg As New MailMessage()
>oMsg.From = New MailAddress(myfromn***@domain.com)
>oMsg.To.Add(New MailAddress***@domain.com)
>oMsg.Subject = "My Subject..."
>oMsg.IsBodyHtml = True
>oMsg.Body = "My HTML...blah..."
>oSmtp.Send(oMsg)
>

Take a look at the AlternateViews propert of MailMessage. By the looks
of it you need to send the main message as plain text, and attach the
richer versions (such as html) as an alternate view. Although I have no
idea how any of that works so you'll just have to play with it (I just
got this by looking at the docs).