Sign in to follow this  
Followers 0
MSLx Fanboy

CDO.Message

2 posts in this topic

I know this might be a stupid question...I don't remember how to check for an error in the CDO.Message Object

Here's the code I'm working with right now...

#include<Array.au3>

;Email Configuration
$Sender = 'home_office@server.com'
$Recipient = 'remote_office@server.com'
$MailServer = 'smtp.server.com'
$MailUser = 'dummy_user'
$MailPass = 'dummy_pass'

;Other Configuration Settings
$PDF_Dir = "C:\scanner\sendmail\emails"
$Blowfish_Password = "password";For Blowfish

Func SendEmail($Attachment)
    
    $objMessage = ObjCreate('CDO.Message')
    With $objMessage
        .Subject = 'EUMatic.de File'
        .Sender = $Sender
        .From = $Sender
        .To = $Recipient
        .TextBody = 'I have another file attached for you to look at.'
        .AddAttachment ($Attachment)
    EndWith
    With $objMessage.Configuration.Fields
        .Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $MailServer
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        .Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $MailUser
        .Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $MailPass
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
        .Update
    EndWith
    $objMessage.Send
    Return 1
EndFunc  ;==>SendEmail

Func FindFiles()
    If Not FileExists($PDF_Dir & "\*.pdf") Then Return 0
    Dim $PDFfiles[1]
    
    $PDFHandle = FileFindFirstFile($PDF_Dir & "\*.pdf")
    While 1
        $file = FileFindNextFile($PDFHandle)
        If $file <> "" Then
            _ArrayAdd($PDFfiles, $file)
            _ArrayInsert($PDFfiles, 0, UBound($PDFfiles) - 1)
        Else
            ExitLoop
        EndIf
    WEnd
    FileClose($PDFHandle)


    For $x = 1 To $PDFfiles[0]
        If Not FileExists($PDF_Dir & "\Encrypted\") Then DirCreate($PDF_Dir & "\Encrypted\")
        If Not FileExists($PDF_Dir & "\Archives\") Then DirCreate($PDF_Dir & "\Archives\")
        RunWait('bfish.exe /I:"' & $PDF_Dir & '\' & $PDFfiles[$x] & '" /O:"' & $PDF_Dir & '\Encrypted\' & $PDFfiles[$x] & '" /P:"' & $Blowfish_Password & '" /E /Q', "", @SW_HIDE)

        SendEmail($PDF_Dir & "\Encrypted\" & $PDFfiles[$x])
        FileMove($PDF_Dir & "\" & $PDFfiles[$x], $PDF_Dir & "\Archives\" & $PDFfiles[$x])
        FileDelete($PDF_Dir & "\Encrypted\" & $PDFfiles[$x])
        $PDFfiles[$x] = ''
    Next
EndFunc

Func ErrorHandler()
    $HexNumber = Hex($oMyError.number, 8)
    
    MsgBox(0, "", "We intercepted a COM Error !" & @CRLF & @CRLF & _
            "err.description is: " & @TAB & $oMyError.description & @CRLF & _
            "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
            "err.number is: " & @TAB & $HexNumber & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
            "err.source is: " & @TAB & $oMyError.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )
    
    SetError(1); to check for after this function returns
    Exit
EndFunc  ;==>ErrorHandler
Dim $oMyError = ObjEvent ("AutoIt.Error", "ErrorHandler")

While 1
    FindFiles()
    Sleep(1000*10)
WEnd

#cs
;;Original Script (prompts user for files)
While 1
    $PDFfiles = FileOpenDialog('Select PDF File(s)', @DesktopDir, 'PDF Files (*.pdf)', 5)
    If @error Then ExitLoop;user hit cancel, exit While loop (cause program exit)
    If StringInStr($PDFfiles, '|') Then;multiple files selected
        $PDFfiles = StringSplit($PDFfiles, '|');separate each file into array for processing
        For $x = 1 To $PDFfiles[0]
            SendEmail($PDFfiles[$x])
            FileMove($PDFfiles[$x], @DesktopDir & '\Archives\' & $PDFfiles[$x])
        Next
    Else;only one file selected, so its a string
        SendEmail($PDFfiles)
        FileMove($PDFfiles, @DesktopDir & '\Archives\' & $PDFfiles)
    EndIf
WEnd
#ce

Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites



*bump*


Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0