A script to send email from your gmail account (VBscript)

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

A script to send email from your gmail account (VBscript)

Post by Rain » Tue Apr 26, 2011 4:57 pm

Submitted by: Rain

This example will send emails from your Gmail account but it can be configured for other SMTP Servers. I use Gmail in this example because it's my preferred email service. See remarks in the script.

Known Issues:
Leaving VBSEmailAttachment empty will result in a noname 0K (Zero K) attachment in the email.

Tested in Windows Windows 7 Ultimate
Written with Macro Scheduler 12.1.4

Code: Select all

VBSTART
Function SendGmail(VBSEmailSubject,VBSEmailFrom,VBSEmailTo,VBSEmailBody,VBSEmailAttachment,VBSEmailServer,GmailUserName,GmailPassword,VBSServerPort,VBSEmailSSL,VBSEmailTimeout)
Const cdoSendUsingPickup = 1 
Const cdoSendUsingPort = 2 
Const cdoAnonymous = 1 
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = VBSEmailSubject
objMessage.From = VBSEmailFrom
objMessage.To = VBSEmailTo
objMessage.TextBody = VBSEmailBody
objMessage.AddAttachment VBSEmailAttachment
'This section provides the configuration information for the remote SMTP server.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = VBSEmailServer
'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = GmailUserName
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = GmailPassword
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = VBSServerPort
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = VBSEmailSSL
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = VBSEmailTimeout
objMessage.Configuration.Fields.Update
objMessage.Send
End Function
VBEND




'Email from
Let>VBSEmailFrom=Your Name <[email protected]>
'Email address to send email to
Let>[email protected]
'Email Subject
Let>VBSEmailSubject=VBscript Email Example by Rain
'Email Body Text
Let>VBSEmailBody=This email was sent with CDO
'Your Gmail UserID
Let>[email protected]
'Your Gmail Password
Let>GmailPassword=XXXXX
'Name of Gmail Remote SMTP Server
Let>VBSEmailServer=smtp.gmail.com
'Gmail Server port (typically 465)
Let>VBSServerPort=465
'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the gmail server)
Let>VBSEmailTimeout=60
'Use SSL for the connection (Must Be True)
Let>VBSEmailSSL=True

//E.g. C:\Log.txt
//Leave Empty for no attachment
//Email will have an empty attachment
Let>VBSEmailAttachment=C:\Log.txt

VBEval>SendGmail("%VBSEmailSubject%","%VBSEmailFrom%","%VBSEmailTo%","%VBSEmailBody%","%VBSEmailAttachment%","%VBSEmailServer%","%GmailUserName%","%GmailPassword%",%VBSServerPort%,%VBSEmailSSL%,%VBSEmailTimeout%),res

Enjoy

hpegar
Newbie
Posts: 9
Joined: Tue May 29, 2012 3:08 pm

Re: A script to send email from your gmail account (VBscript

Post by hpegar » Mon Nov 12, 2012 10:47 pm

I tried this code and get> Error 1033
Any ideas?

hpegar
Newbie
Posts: 9
Joined: Tue May 29, 2012 3:08 pm

Re: A script to send email from your gmail account (VBscript

Post by hpegar » Mon Nov 12, 2012 10:49 pm

hpegar wrote:I tried this code and get> Error 1033
Any ideas?
GetDialogProperty>Dialog1,Sysinfo,Text,copiaresto
Let>VBSEmailBody=copiaresto

Seems like this is the mistake :'( Sorry

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts