'-------------------------------------------------------------------- ' mail_1.vbs '-------------------------------------------------------------------- Dim strTo, strSubject, strTextBody, strFrom, strCC, strBCC Dim strTextBodyFile, strAttachment1, strAttachment2 strSubject="Subject of the message" 'fill in your SMTP server strSMTPServer="mail.westernsydney.edu.au" 'fill in your email address strFrom="?????@??????? " 'fill in the receiver's email address strTo="????@??????" strCC="" strBCC="" 'fill in the emailBody file name with full path. The message is composed in a text file "emailBody.txt" strTextBodyFile="Z:\Teaching\ScrProg09\Lectures\Lecture8\emailBody.txt" 'fill in the path for one attachment strAttachment1 = "Z:\Teaching\ScrProg09\Lectures\Lecture8\attachFile1.txt" 'fill in the path for another attachment strAttachment2 = "Z:\Teaching\ScrProg09\Lectures\Lecture8\attachFile2.txt" main function main strTextBody = ReadTextFile(strTextBodyFile) mail strFrom, strSubject, strTextBody, strTo, strCC, strBCC, _ aAttachment, strSMTPServer msgbox "Message sent successfully" end function sub mail(strFrom, strSubject, strTextBody, strTo, strCC, strBCC, _ aAttachment, strSMTPServer) Dim objMessage, objConfiguration, objConfigFields Set objConfiguration = CreateObject("CDO.Configuration") Set objConfigFields = objConfiguration.Fields objConfigFields.Item("http://schemas.microsoft.com/cdo/" & _ "configuration/sendusing") = 2 objConfigFields.Item("http://schemas.microsoft.com/cdo/" & _ "configuration/smtpserverport") = 25 objConfigFields.Item("http://schemas.microsoft.com/cdo/" & _ "configuration/smtpserver") = strSMTPServer objConfigFields.Update Set objMsg = CreateObject("CDO.Message") objMsg.Configuration = objConfiguration objMsg.From = strFrom objMsg.Subject = strSubject objMsg.TextBody = strTextBody objMsg.To = strTo objMsg.CC=strCC objMsg.BCC=strBCC objMsg.AddAttachment(strAttachment1) objMsg.AddAttachment(strAttachment2) objMsg.Send end sub function ReadTextFile(strFileName) Dim objFSO Dim objTextFile Dim strReadLine Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile(strFileName,1) do while not objTextFile.AtEndOfStream strReadLine = strReadLine + objTextFile.ReadLine() loop objTextFile.Close() ReadTextFile = strReadLine end function