Posts Tagged ‘smtp’

Send Mails Via Remote Server With VBScript (Windows)

Wednesday, November 16, 2011 posted by CSch

You can use MS Windows’ VBScript to write a script that is able to log into a remote mail server such as googlemail or any other with your account data and send mails from that server. This can be used to retrieve logs via attachments or to just automate mail processes. The bare script to send a mail looks as follows (the apostrophe after a line signals a comment to the lines content, it does not belong to the script. The data all go inside the doublequotes if there are any):

Set objMessage = CreateObject(“CDO.Message”)

objMessage.Subject = “Type in the mail’s subject here

objMessage.From = “ <the sender mail goes here, you need the login data for it>
‘The mail address goes inside the tags

objMessage.To = “the receiver mail goes here

objMessage.TextBody = “Here goes the actual mail message

objMessage.Addattachment “Fill in the complete path to your attachment, otherwise leave complete line

objMessage.Configuration.Fields.Item _
(“”) = 2
determines whether you use local smtp (1) or network (2)

objMessage.Configuration.Fields.Item _
(“”) = “
Fill in your smtp (outgoing) server
You can find your provider’s server address somewhere on the homepage or by googling for smtp server lists

objMessage.Configuration.Fields.Item _
(“”) = 1
Determines the authentication mode. 0 for none, 1 for basic (clear text), 2 for NTLM

objMessage.Configuration.Fields.Item _
(“”) = “
should be the same as the sender mail – login data for your server

objMessage.Configuration.Fields.Item _
(“”) = “
your email’s password – login data for your server

objMessage.Configuration.Fields.Item _
(“”) = 25
This is the default port used by most servers. Find out if yours is using a different one if there are problems

objMessage.Configuration.Fields.Item _
(“”) = False
Use SSL? True or False

objMessage.Configuration.Fields.Item _
(“”) = 60

Maximum time connection is tried to be established



It is recommended not to use this script on a computer you are not the only user of, since your email and its password are openly visible. However you can just create a new one for that purpose. You can easily embed this script into any other VBScript, schedule it or do whatever you want with it.