VBScript Class to Send Mail With CDOSYS

John Avis by | February 16, 2008 | Classic ASP Web Development

This is my first attempt at a VBScript class.

It allows full control of the CDO Message object.

You can create a new instance of the class with the following:

Dim clsSendMail
Set clsSendMail = New SendMail

Then add the various properties of the email:

clsSendMail.SendTo = "test@test.com"
clsSendMail.From = "test@test.com"
clsSendMail.Subject = "Test Message"

Next you choose what type of mail you are going to send: plain text, HTML or from a URL or local file.

Type Property/Method Syntax
Plain Text TextBody clsSendMail.TextBody = "message here"
HTML HTMLBody clsSendMail.HTMLBody = "<b>html</b> message here"
URL CreateMHTMLBody Call clsSendMail.CreateMHTMLBody "http://www.url.com/pagename.htm"
Local File CreateMHTMLBody Call clsSendMail.CreateMHTMLBody "file://c:/mydocuments/test.htm"

To add an attachment use the following:

Call clsSendMail.AddAttachment "c:\mydocuments\test.txt"

To embed files in your message use:

clsSendMail.AddRelatedBodyPart "/older/imagefile.gif", "image1.gif"

This can then be included in your HTMLBody by referencing the second parameter as the CID, for example:

<img src="cid:image1.gif">

You can also set a SMTP server and port if neccessary:

Call clsSendMail.SMTPServer "mail.test.com", 25

SendMail Class

Related Posts

Intermittent "Unable to read data from the transport connection: net_io_connectionclosed" errors

by John Avis | May 6, 2020

If you are having intermittent problems sending email in .NET using System.Net.Mail consider switching libraries.

500 Internal Server Error after migrating from IIS 7.5 to IIS 10

by John Avis | November 4, 2019

As support ends for Microsoft Windows Server 2008 I have recently gone through migrating some websites to a new server running Windows Server 2016 and IIS 10 but some of the websites did not work.

tagInput: A simple jQuery plugin for tag entry using Bootstrap 4

by John Avis | October 15, 2019

For a website project I needed a way to enter multiple tags. I just wanted something simple that I could easily modify to suit my own needs, so I wrote my own.


There are no comments yet. Be the first to leave a comment!

Leave a Comment



...random postings about web development and programming, Internet, computers and electronics topics.

I recommend ASPnix for web hosting and Crazy Domains for domain registration.


Get the latest posts delivered to your inbox.