Today, I want to talk about getting in shape to run the Microsoft Exchange, SMTP Relay. It takes years of practice to get in condition for such a grueling race. I am just kidding!
However, the topic of a SMTP relay is an important one that you will come across in your career. A open mail relay allows a Visual Basic script to send mail messages from a mail box that you can name and does not have to exist on the mail server.
In todays information world, it is very important to stay connected via emails. Emails can be used for many different purposes in your Visual Basic scripts.
- Alerting when system thresholds or conditions are met
- Notification when automated tasks complete or fail
- Delivery of custom reports and messages to users.
I have encapsulated the logic for running the SMTP relay, via Collabortion Data Objects (CDO), into a abstract class.
The CDO Email class has the following required properties.
SMTP_SVR – The DNS name of the MS Exchange (mail) server
FROM_EMAIL – Any source email address that follows naming conventions.
TO_EMAIL – A valid destination email address.
MSG_SUBJECT – A string describing the subject of the message.
MSG_BODY – A textual or html string that contains the body of the message.
The CDO Email class has the following optional properties that allow the designer to send HTML message bodies, add multiple attachments, and set mail priority levels.
CC_EMAIL – A valid destination (carbon copy) email address.
BCC_EMAIL – A valid destination (blind carbon copy) email address.
BODY_TYPE – Defaults to text. Is required if you want HTML body to be translated.
MSG_ATT = A tilda seperated string of full qualified file names to be attached to the message.
MSG_PRIOIRITY – A value indicating low (0), normal (1), or high (2) priority.
This class contains two methods that can be called to do the following actions.
LOAD_BODY- This method loads a given file as text and save it as the MSG_BODY property.
SEND_EMAIL – This method creates the message and sends it to the mail server.
The table below has starter code that you can use in your next Visual Basic (VB) Script.
|mod-cdo-email.vbs||CDO Email Class|
|tst-cdo-mail.html||Sample HTML Message|
|Wikipedia Image||Sample Image Attachment|
The output below was generated by the execution of the test program with two sub-routines.
First routine creates an text email with varying importance levels. The email notifies users that the Boston Bruins won the Stanley Cup in 2011.
Secound routine creates an HTML email with a image attachment. The focus of this message is the 16th president, Lincoln Abraham.
To recap this discussion, dynamic email creation is used all the time by software systems. Adding the SMTP relay component to your VB Script solution will keep you end users aware of recent events.