In FOCUS since 1986 | WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2 | ||
WebFOCUS App Studio 8.2.06 standalone on Windows 10 |
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' Description : VB Script module to send emails with attachments using CDONT (Windows) ' Written By : Anthony Alsford EDATA Limited 05/01/2009 ' Notes : This script MUST be executed from a machine that DOES NOT block certain ' ports via AntiVirus software or Firewall ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ On Error Resume Next ' First declare constants Const cdoSendUsingPickup = 1 Const cdoSendUsingPort = 2 'Must use this to use Delivery Notification Const cdoServerPort = 25 Const cdoAnonymous = 0 Const cdoBasic = 1 'clear text Const cdoNTLM = 2 'NTLM ' Delivery Status Notifications Const cdoDSNDefault = 0 'None Const cdoDSNNever = 1 'None Const cdoDSNFailure = 2 'Failure Const cdoDSNSuccess = 4 'Success Const cdoDSNDelay = 8 'Delay Const cdoDSNSuccessFailOrDelay = 14 'Success, failure or delay Const cdoIPAddress = nnn.nnn.nnn.nnn 'The IP address of your SMTP server Const cdoEmail = yourname@yourdomain.etc 'The Email address you wish to use for send and return address ' Now Dim and set required objects Dim fso, logfile, errfile set fso = Wscript.CreateObject("Scripting.FileSystemObject") set logfile = fso.CreateTextFile("E:\test_scripts\EMail.log") set errfile = fso.CreateTextFile("E:\test_scripts\EMail.err") ' Set up the CDO configuration - the mail component needs to be achieved for each mail to be sent so is actioned later set objConf = CreateObject("CDO.Configuration") Set Flds = objConf.Fields ' Set the CDOSYS configuration fields to use port 25 on the SMTP server. With Flds .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = cdoIPAddress .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = cdoServerPort .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoNTLM .Item("urn:schemas:mailheader:disposition-notification-to") = cdoEmail .Item("urn:schemas:mailheader:return-receipt-to") = cdoEmail .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10 .Update End With ' Set the body of the email - this should be split across lines to ensure that no line exceeds 1000 characters strBody = "This is an automated Email - DO NOT RESPOND." & vbCRLF & vbCRLF & vbCRLF strBody = strBody & "Regards" & vbCRLF & vbCRLF strBody = strBody & "The PCC Team" & vbCRLF & vbCRLF ' Check to see that the file exists before trying to email it! If fso.FileExists("drive:\fullpath\yourfilename.extn") Then ' Do something set objMsg = CreateObject("CDO.Message") With objMsg Set .Configuration = objConf .To = somename@domain.com .From = cdoEmail .Subject = "The subject line" .TextBody = strBody ' use .HTMLBody to send HTML email. .Addattachment "drive:\fullpath\yourfilename.extn" .DSNOptions = cdoDSNFailure .Send End With If Err.Number <> 0 Then errfile.Write "Error sending Email" errfile.Write "Error: " & Err.Number errfile.Write "Error (Hex): " & Hex(Err.Number) errfile.Write "Source: " & Err.Source errfile.Write "Description: " & Err.Description Err.Clear logfile.Write "email transit error " & vbCRLF Else logfile.Write "email sent OK" & vbCRLF End If set objMsg = nothing Else logfile.Write "file attachment does not exist " & vbCRLF End IfIf anyone uses this code then a donation to their local cancer charity would be very much appreciated.
In FOCUS since 1986 | WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2 | ||
WebFOCUS App Studio 8.2.06 standalone on Windows 10 |