For many years it is possible to send emails from scripts/command line.
One of the best known programs is blat (blat.exe).
When you are scripting in VBscript it is more convenient to send an email with vbs instead of calling other executables.
This script contains a function which takes two variables, the recipient and the header.
With a little modification the function can handle more variables.
Follow the next steps to make and run the script (no admin rights needed):
- open your favorite text editor (mine is notepad++)
- copy and paste the script into the editor (delete the line numbers)
- save the script (for example c:tempsendmail.vbs)
- open a command prompt
- go to “c:temp”
- give “cscript sendmail.vbs” (without quotes) and enter
The script:
' Name : sendmail.vbs
' Description : script to send an email (needs an smtp server)
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 10-02-2010
' Level : beginner
Sendmail "test@recipient.org","this is a testmessage"
Function SendMail(strRecipient, strHeader)
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = strHeader
objMessage.From = "testuser@test.org"
objMessage.To = strRecipient
objMessage.TextBody = "This is an automated message"
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "your.smtp.server.here"
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objMessage.Configuration.Fields.Update
objMessage.Send
Set objMessage = Nothing
End Function
When you have problems/questions please post a reply.
Happy scripting.
Dirk Adamsky – Deludi BV

I have a script that reads an excel spreadsheet for email addresses. The email addresses are from one (stremail1) to a maximum of 4 (stremail4). Puting objMessage.To = stremail1 stremail2 streemail3 stremail4 does not work nor does
objMessage.To = stremail1
objMessage.To = stremail2
objMessage.To = stremail3
objMessage.To = stremail4
How do I get more than one email address in the “objMessage.To =” line ?
Thanks
Otis Hopkins
Hi Otis,
Sorry for my late reply.
You have multiple options:
1.
create a distributionlist in AD/Exchange
fill the list with the desired members
use the sendmail function to send to the distributionlist smtp address
2.
when you do not want to use a distributionlist you can also call the ‘Sendmail’ function multiple times:
Example:
Sendmail “test1@recipient.org”,”this is a testmessage”
Sendmail “test2@recipient.org”,”this is a testmessage”
Sendmail “test3@recipient.org”,”this is a testmessage”
Sendmail “test4@recipient.org”,”this is a testmessage”
Hope that gives you some help with your script.
Best regards,
Dirk Adamsky