Monday 20 June 2011

VB Script to send email

VBscript to send email without SMTP service running on your local machine:
dont burn up your mind to know how..
just copy and paste the below vbscript in a notepad and save with the name say send.vbs
you can also copy the below code to embed within your custom developed programs (.net/ aspx/..)
I have tested this in the access, .aspx for sharepoint, and customised applications. You wont believe  this can be also embedded within Excel if you are interested in getting an email every time an excel file is updated by someone in your organisation.. what you are waiting for just adapt and transform the below code :)
'------------------------------------ vbscript begins here
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "User account unlocked"
objMessage.From = "itsupport@yourdomain.com"
objMessage.To = "abc@yourdomain.com"
objMessage.TextBody = "This is some sample message text."
'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "your smtp server address, can also specify IP address"
'Server port (typically 25 or check with your exchange admin)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==
objMessage.Send



'-------------------------------------------------------- vbscript ends here



you can either execute the above script manually, or create a scheduler task to execute the above .vbs so that it can be used as an automated process.



To know more about Ports and how to independently search for it from your machines without an domain admins assistance.. will be posting the infos soon under IT» Scripts and Tips Unleashed .
please comment if you have better suggestion so that I can review, test and share the info.

0 comments: