How to send an email using gmail and windows script….

Wouldn’t it be nice to run the script daily, or multiple times a day and have it automatically email with problems? To do that, you need to know how to send an email within script. If you research online, you’ll discover dozens (or more) ways people accomplish this. By far, the most popular is using the CDO approach.

<job>
<script language="VBScript">
Option Explicit
On Error Resume Next

Const fromEmail = "rdxxxx@gmail.com"
Const password = "xxxxxxxx"

Dim emailObj, emailConfig
Set emailObj = CreateObject("CDO.Message")
emailObj.From = alert@topsecretwriters.com
emailObj.To = "rdxxxxx@gmail.com"
emailObj.Subject = "Test Email"
emailObj.TextBody = "It Works!!"

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") = fromEmail
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = password
emailConfig.Fields.Update
emailObj.Send
Set emailobj = nothing
Set emailConfig = nothing
WScript.Quit

</script>
</job>

The above script will let you send any text for the message body as an email to any address using your Gmail credentials. You could modify the parameters to use any other SMTP mail server you like.

This entry was posted in email, Gmail. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *