Create a message containing all the files in a directory and send it with the SMTPClientObject
' Example: CSMail VBScript Example 3
' Summary: Create a message containing all the files in a directory and
' send it with the SMTPClientObject
' Usage: cscript exvbs03.vbs
' or
' wscript exvbs03.vbs
set MyMsg=CreateObject("CSMail.Message") ' Create the message object
MyMsg.Subject="Medical Officer's Report" ' Set the message subject
MyMsg.To(1)="[email protected]" ' Set the recipient...
MyMsg.From(1)="[email protected]" ' ... and the originator
MyMsg.Sections(1).Body="Its life Jim, but not as we know it."
' Set the message body text
' See the Microsoft Windows Scripting Host Documentation for details
' of the FileSystemObject model
Set fso=CreateObject("Scripting.FileSystemObject")
Set folder=fso.GetFolder("v:\test")
for each file in folder.files ' Iterate through the files
wscript.echo file.name ' Diagnostics (see WSH docs re wscript.echo)
set s=MyMsg.Sections.Add ' Create a new section in the current message
s.AttachBodyFromFile(file.Path) ' Attach the file
next
set SMTP = CreateObject("CSMail.SMTPClient") ' Create an SMTP Client Object
SMTP.Connect("127.0.0.1") ' Connect to the server - in this case the local machine
wscript.echo "Sending..."
SMTP.SendMessage(MyMsg) ' Send the message
wscript.echo "Sent..."
SMTP.Close ' Close the server
|