×
Menu
Index

3.6.5.2. Send Email on Errors (OnExportFinish)

 
This sample script will send an email on the OnExportFinish step of the Hotfolder workflow. If there are errors during export of the current Batch.
Following the two example codes below the only changes needed are the SMTP server settings such as strSMTPFrom, strSMTPTo, strSMTPRelay, strAttachment (if desired), oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 and oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2.
The same kind of code can be used for sending out emails right after document processing by using the Execute VBScript option instead of the HotFolder mode option on the Tasks & Process Menu on the Document Document Toolbar on the Scan/Input Tab.
 
 
To execute the code using hotfolders select the HotFolder option for the VBScript.
 
 
Set Batch = ChronoApp.GetCurrentBatch
 
BatchName=Batch.GetName
NumDocs=Batch.GetDocCount
ExportStatus=Batch.GetExportStatus
 
' ExportStatus =  3 means error on export. Validation errors were detected while exporting. Click here to learn more about ExportStatus for Batches.
 
If ExportStatus=3 Then
 
    strSMTPFrom = "Somebody@somehwhere.com"
    strSMTPTo = "anotherrecipient@somedomain.com"
    strSMTPRelay = "yourrelay.domain.net"
    strTextBody = ""
    strSubject = BatchName & " had errors during export"
    'strAttachment = "c:\attachment_file.pdf"
 
 
    Set oMessage = CreateObject("CDO.Message")
    oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPRelay
    oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    oMessage.Configuration.Fields.Update
 
    oMessage.Subject = strSubject
    oMessage.From = strSMTPFrom
    oMessage.To = strSMTPTo
    oMessage.TextBody = strTextBody
    'oMessage.AddAttachment strAttachment
 
 
    oMessage.Send
 
Else
End If
 
An alternative to that code follows:
 
Set Batch = ChronoApp.GetCurrentBatch
Dim NumDocs
Dim errDocs
NumDocs=Batch.GetDocCount
 
'navigating records to find number of error documents
errDocs=0
For numDoc = 0 To NumDocs-1
    If(Batch.IsValidated(numDoc))=0 Then
        errDocs=errDocs+1
    Else
    End If
Next
 
If errDocs > 0 Then
 
    strSMTPFrom = "no-reply@yourcompany.com"
    strSMTPTo = "joe@gmail.com"
    strSMTPRelay = "relay.isp.net"
    strTextBody = "Number of errors = " & errDocs
    strSubject = "Subject line"
    'strAttachment = "c:\this_attachment.pdf"
 
 
    Set oMessage = CreateObject("CDO.Message")
    oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPRelay
    oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    oMessage.Configuration.Fields.Update
 
    oMessage.Subject = strSubject
    oMessage.From = strSMTPFrom
    oMessage.To = strSMTPTo
    oMessage.TextBody = strTextBody
    'oMessage.AddAttachment strAttachment
 
 
    oMessage.Send
 
    Else
End If