Welcome
Login  |  Register
Tuesday, January 06, 2009
  Search
You are here:Knowledge Base
 
 
 

 Please Register or login to view our private forums, it is free!!

Subject: vbs script to send out email
Prev Next
You are not authorized to post a reply.

Author Messages
cmuenchUser is Offline
Posts:59

12/11/2007 9:29 AM  

Call the script like this

wscript script_name.vbs

[vbs]

' Define who the email is sent from, must be in valid format (can be bogus address)
emailFrom = "from@example.com"
' Define who the email is sent To
email_arr = array("to@example.com","to2@example.com")
' Define the SMTP server to handle the email
SMTPserver = "smtp.example.com"
' Define the SMTP server port to used
'*** Line 40
SMTPport = "27"
'Define the SMTP username to send
SMTPuser = "smtp_username"
'Define the SMTP password for the above user
SMTPpasswd = "smtp_password"
' Send the email out
' split string into array
' loop through array and call SendEmail sub
for Each email in email_arr
  SendEmail(email)
next
sub SendEmail(emailTo)
' Define the action
Set objEmail = CreateObject("CDO.Message")
' Who, What, Where, When, Why, How
objEmail.From = emailFrom
objEmail.To = emailTo
' Edit the subject and body as required...
objEmail.Subject = "This is the Subject of the Email"
objEmail.Textbody = "This is your message body.  I usually include the timestamp inside " & Now()
' Define email server settings
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPserver
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = SMTPuser
'Your password on the SMTP server
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = SMTPpasswd
'Server port (typically 25)
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTPport
'Use SSL for the connection (False or True)
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objEmail.Configuration.Fields.Update
' Send the EMAIL
objEmail.Send
End Sub
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

' Stop the script in case it doesn't automatically
WScript.Quit

[/vbs]

You are not authorized to post a reply.
Forums > Knowledge Base Systems > Windows > vbs script to send out email



ActiveForums 3.7
 
Copyright 2006-7 Vigilant Support