Monday, June 04, 2012

How to send a email using VB Script.

Some times requirements occurs to send email from Windows environment. it may be due to server monitoring or application monitoring purpose or may be some other need. Lot of third-party applications in the internet and you can try those your own. But most light weight and slandered way to send email from windows environment is the VB script. Using VB Script is very easy and simple. following is the way to send a email using VB Script. this can be help to your script development and system monitoring purpose.

Dim objMail

Set objMail = CreateObject("CDO.Message")

'sender email address
objMail.From = "Sender <>"

'Receiver email address
objMail.To = "Receiver <>"

'Email subject
objMail.Subject = "This is the testing email subject"

'Email Body
objMail.Textbody = "This is the my first email send by vb script"

'If you need to attache a file,can do in this way.
objMail.AddAttachment "C:\myphoto.jpg"

'Configure SMTP server
objMail.Configuration.Fields.Item _
    ("") = 2

'Here you should configure name or IP of the SMTP server
objMail.Configuration.Fields.Item _
    ("") = _

' SMTP port need to configure here (Default 25)
objMail.Configuration.Fields.Item _
    ("") = 25

'update the field in message object 

'sending email

'clear mail object
Set objMail=Nothing

'exit the script