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:\temp\sendmail.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
Recent Comments