[Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 713
  • Last Modified:

Send Multipart Email - Plain and HTML

Trying to send a multipart email and not sure if it is working right.  
It is part of an asp website.  
Currently being sent by CDOSYS with:

objMail.TextBody = "This is a plain text message"
objMail.HTMLBody = HTML

Is this the correct method?  Or should it be done some other way.
How do I tell if it is working.  
Any mail client I have sent it to is showing the html.  
When I change Outlook 2003 to show Plain Text Email it just seems to strip the html tags out of the html version rather than showing the Plain Text Version.  
Should both parts be in the email headers?  Or how do I check that both parts have actually been sent?
  • 2
  • 2
  • 2
1 Solution
Looks like you are declaring the email content as plain text and then over-riding this with a declaration that the content is HTML. Strip out the line objMail.HTMLBody = HTML and try sending.
Code Outline Below Helps you send both version of eMails.

You can change the code according to your need.

Hope this helps.
'We start by creating a mail object and a configuration object to use 
'with it:
  Set oCdoMail = Server.CreateObject("CDO.Message")
  Set oCdoConf = Server.CreateObject("CDO.Configuration")
'Set the configuration object up as shown below. You might have to 
'change the SMTP server item from "localhost" to point to your web 
'hosts SMTP server. The default port is 25, which you may also have to 
'change - again, check with your web host.
  sConfURL = "http://schemas.microsoft.com/cdo/configuration/"
  with oCdoConf
    .Fields.Item(sConfURL & "sendusing") = 2
    .Fields.Item(sConfURL & "smtpserver") = "localhost"
    .Fields.Item(sConfURL & "smtpserverport") = 25
  end with
'Now we can set up our recipients. You can send to multiple recipients 
'by seperating addresses with a semicolon, as shown with the To 
'property below:
  with oCdoMail
    .From = "you@yourdomain.com"
    .To = "someone@domain.com; somebody@domain.com"
    .CC = "someone.else@domain.com"
    .BCC = "someone@anotherdomain.com"
  end with
'Set the Subject and Body text and we're almost there. To send plain 
'text email, use the TextBody method. To send HTML email, use the 
'HTMLBody method.
'You can also add an attachment to your message by using the 
'AddAttachment method:
  with oCdoMail
    .Subject = "My message subject"
    .TextBody = "This is a plain text email"
    .HTMLBody = "<b>This is an HTML email</b>"
    .AddAttachment = "C:\Inetpub\wwwroot\attachment.zip"
  end with
'And that's just about it, all we need to do now is bind the 
'configuration to the CDO Message and send the email:
  oCdoMail.Configuration = oCdoConf
  Set oCdoConf = Nothing
  Set oCdoMail = Nothing

Open in new window

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

harris9999Author Commented:
Thats exactly how I am sending the email at the minute.  
But I'm not sure if both the text/plain bit and the HTML are being sent in the one message.  

It is a sort of mailing application and it is good practice to send both versions in the one email.  
The mail is being sent and is being received fine.  And the html is showing.  But how do I know if the plain part was sent as well as the html part.  
It may be difficult to view all the parts of your e-mail message at the same time. View|Source may only show the HTML portion of the message. Without Outlook 2000, the only way I can view both parts of the message is to forward an HTML message to a non-existent e-mail address. When the bounced message comes back I'm able to see each part of the multipart message.

Hope this helps

harris9999Author Commented:
I had a good search on the internet and it mentioned that Thunderbird supported multipart emails.  So downloaded and set up and account and it was able to show the plain text version when I put it to Plain Text mode.  and the HTMl in normal mode so I'm now happy that my code was working correctly.  

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now