Thursday, October 27, 2011

Send e-mail from windows using windows script hosting.

Let me think...Yes it will definitely come in handy. No need to open gmail or yahoo or some other email clients to send an e-mail. If you are having an Internet Connection which is even slower than the ants crawling in the walls or you are having a bad day and you some important stuffs to send, then definitely this script will do your Job.

Copy the below code to notepad and save it as email.wsf


<job>
<script language="VBScript">
Option Explicit
On Error Resume Next


Const fromEmail = "jamesbond@gmail.com"
Const password = "007ismypassword"


Dim emailObj, emailConfig
Set emailObj = CreateObject("CDO.Message")
emailObj.From = "jamesbond@gmail.com"
emailObj.To = "ac3gam3r@yahoo.com"
emailObj.Subject = "Test Email"
emailObj.TextBody = "It Works!!"


Set emailConfig = emailObj.Configuration
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = fromEmail
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = password
emailConfig.Fields.Update
emailObj.Send
Set emailobj = nothing
Set emailConfig = nothing
WScript.Quit
</script>
</job>


Replace your email address with the code marked in  italics accordingly.
This script is to send an email from gmail and all the settings are according to it. So if you want to send from other email clients, then accordingly set the smtp address.

Enjoy. Happy scripting.

0 comments:

Post a Comment

 

Tech. Arcade Copyright © 2011