Email via VBScript using CDO

The best way to use this script is to first create an email service account, and then just add the details of the service account to the below script. I also recommend compiling this script once you have it working with your email service account.

on error resume next

‘SET EMAIL CONTENT HERE – THIS COULD BE DYNAMIC CONTENT
GMail_Subject = “YourSubjectHere”‘This could be a username, topic, or other dynamic information
Gmail_Body = “Email Script” & vbCRLF & “Script created by Eddie Jackson” & vbCRLF & “Variables can be added here like bitlocker info, username, computer name, etc.”

‘MAIL OBJECTS
Const cdoSendUsingPickup = 1
Const cdoSendUsingPort = 2
Const cdoAnonymous = 0
Const cdoBasic = 1
Const cdoNTLM = 2

‘EMAIL ACCOUNT INFORMATION – ONLY NEEDS EMAIL SERVICE ACCOUNT INFO
Const strFrom = “HomeUsername@gmail.com”
Const strFromName = “FromInfoHere”
Const strTo = “EMAIL_ADDRESS_1@gmail.com,EMAIL_ADDRESS_2@gmail.com”‘who you want to receive the email
Const Gmail_SMTPServer = “smtp.gmail.com”
Const GMail_SMTPLogon = “EmailServiceAccountEmailAddressHere”’email service account
Const Gmail_SMTPPassword = “EmailServiceAccountPasswordHere”‘service account password
Const SMTPSSL = True
Const SMTPPort = 465

‘EXECUTES OBJECTS
Set objMessage = CreateObject(“CDO.Message”)
objMessage.Subject = GMail_Subject
objMessage.From = “””” & strFromName & “”” <” & strFrom & “>”
objMessage.To = strTo
objMessage.TextBody = Gmail_Body

objMessage.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/sendusing”) = 2
objMessage.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/smtpserver”) = Gmail_SMTPServer
objMessage.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/smtpauthenticate”) = cdoBasic
objMessage.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/sendusername”) = GMail_SMTPLogon
objMessage.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/sendpassword”) = Gmail_SMTPPassword
objMessage.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = SMTPPort
objMessage.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/smtpusessl”) = SMTPSSL
objMessage.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout”) = 60
objMessage.Configuration.Fields.Update

‘THIS SENDS THE MESSAGE
objMessage.Send

email me