b1nary0mega
1/7/2015 - 4:35 PM

Send email using VBScript

Send email using VBScript

Sub Send_Email()
'
' Send_Email Macro
' send an email
'
' Keyboard Shortcut: Ctrl+Shift+E
'
   
Set emailObj = CreateObject("CDO.Message")

emailObj.From = "Username@gmail.com"
emailObj.To = "IntendedRecipient@gmail.com"

emailObj.Subject = "Test CDO subject"
emailObj.TextBody = "Test CDO body"

Set emailConfig = emailObj.Configuration

emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "Username@gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "UserPasswordHere"

emailConfig.Fields.Update

emailObj.Send

If Err.Number = 0 Then MsgBox "Email Sent!"

End Sub