Const cdoSendUsingPickup = 1

Const cdoSendUsingPort = 2

Const cdoDSNDefault = 0 ‘None

Const cdoDSNNever = 1 ‘None

Const cdoDSNFailure = 2 ‘Failure

Const cdoDSNSuccess = 4 ‘Success

Const cdoDSNDelay = 8 ‘Delay

Const cdoDSNSuccessFailOrDelay = 14 ‘Success, failure or delay

set objMsg = CreateObject(“CDO.Message”)

set objConf = CreateObject(“CDO.Configuration”)

Set objFlds = objConf.Fields

With objFlds

.Item(“http://schemas.microsoft.com/cdo/configuration/sendusing“)
= cdoSendUsingPort

.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserver“)
= “<changeme – server ip or name>”

.Update

End With

strBody = “<change me – body of email message>” & vbCRLF

With objMsg

Set .Configuration = objConf

.To = “<Changeme – emall addresses separate by a semi colon>”

.From = “<changeme – form email address>”

.Subject = “<changeme – subject of email>”

.TextBody = strBody

.Addattachment “<changeme – path to attachment>”

.Fields(“urn:schemas:mailheader:disposition-notification-to”) = “<changeme- email address of admin”
.Fields(“urn:schemas:mailheader:return-receipt-to”) = “<changeme – email address of admin”

.DSNOptions = cdoDSNSuccessFailOrDelay

.Fields.update

.Send

End With

Copy and paste to a text file.  Change all the <Changeme> text to your liking.  Helpful to run as a scheduled task to email attachments or general emails for server monitoring things.  Combine with SQL Database size scripts or mailbox size scripts to get emailed reports at a set schedule.

One thought on “Scripting: Email via Visual Basic Script – VBS

Leave a Reply