|
Starting Windows 2000 there is Collaboration Data Objects (CDO) library supplied with the COM infrastructure.
It simplifies a lot many activity, including send mail tasks.
Here is an example of the vbs script that you may use as an example of implementing send mail task in your WSH script.
Const cdoSendUsingPickup = 1 'Use this constant to send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Use this contant to send the message using the network (SMTP over the network).
Const cdoAnonymous = 0 'Use this contant to do not use authentication
Const cdoBasic = 1 'Use this contanct to use basic (clear-text) authentication
Const cdoNTLM = 2 'Use this constant to use NTLM auth
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example using CDO Message"
objMessage.From = """John Sender""<john.sender@smartsoftwarebits.com>"
objMessage.To = "receiver@smartsoftwarebits.com"
objMessage.TextBody = "Hello." & vbCRLF & "It was sent using WSH and CDO"
'Uncomment this if you need to send an attachement also
'objMessage.AddAttachment "c:\temp\readme.txt"
'Set the method of sending. In this example we set it to cdoSendUsingPort (SMTP over the network)
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
'Set the name or IP of the remote SMTP server
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.google.com"
'Set thetype of authentication. We use basic in the example.
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
'Set your user id in case you use authentication
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "youruserid"
'Set your password in case you use authentication on SMTP server
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpassword"
'Set server port (usually 25)
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
'Set if you would like to use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
'Sett the connection timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
'Finally activate the configuration
objMessage.Configuration.Fields.Update
'Send the message
objMessage.Send
That's it.
Hope this helps. |