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

S

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([email protected])
oMsg.To.Add(New MailAddress([email protected])
oMsg.Subject = "My Subject..."
oMsg.IsBodyHtml = True
oMsg.Body = "My HTML...blah..."
oSmtp.Send(oMsg)
 
C

Chris Chilvers

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([email protected])
oMsg.To.Add(New MailAddress([email protected])
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).
 

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