Send Email by Script or Batch command

Tags: smtp

Sometimes you want to send Email using a Script or a batch file. You can use an external .exe as a tool, but if you have a SMTP-Server in your network reachable, you can use this simple vbs script. Just past in the following code in a Texteditor, modify the values for your Server and the Email-Addresses and save it as .vbs file. Then you can send email from automated tasks.

Set objEmail = CreateObject("CDO.Message")

objEmail.From = "sender@example.com"
objEmail.To = "receipient@example.com"

objEmail.Subject = "Subject: Test – Email by script"
objEmail.Textbody = "This is the Messagetext"

objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.example.com"
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update

objEmail.Send

Greets – Helmut

Add a Comment