Jump to content

CDO.Message Error


Recommended Posts

So I'm helping someone with a small project...and its nearly done, but then the object fails on me when I try to send the email...All of the settings were correct when I did it, and I'm using .56 at the moment. (It's the FileSend Func)

Remember when you're Driver's Ed teacher shows you an egg and smashes it on the ground, showing you how you might end up after a car crash, that's how my brain feels right now...

$g_szVersion = 'EUMatic PDF Mailer'
If WinExists($g_szVersion) Then Exit; It's already running
AutoItWinSetTitle($g_szVersion)

$Blowfish_Password = 'password';For Blowfish

#region SendMail Configuration
;Email Configuration
$Sender = 'sender@address.com'
$Recipient = 'recipient@address.com'
$SMTPServer = 'smtp.address.com'
$SMTPUser = 'smtpuser'
$SMTPPass = 'smtppassword'
$POP3Server = 'pop3.address.com'
$POP3User = 'pop3user'
$POP3Pass = 'pop3password'

;Other Configuration Settings
$PDF_Dir = @DesktopDir & '\PDF'
#endregion

#region GetMail Configuration
$GSPrintDir = 'C:\Program Files\Ghostgum\gsview';Pfad zu Gsview
$source = @ScriptDir & '\Emails'; Pfad der auf neue Dateien überwacht werden soll
$dest = @ScriptDir & '\archives'; Pfad, in den die Dateien nach dem Drucken verschoben werden sollen
$pathtogetmail = @ScriptDir; Pfad, in dem die getmail.exe ist inkl. getmail.exe
#endregion

#region GetMail Functions
Func GetMail()
    MsgBox(0, "test", "starting getmail function", 1)
    RunWait($pathtogetmail & '\getmail.exe -u ' & $POP3User & ' -pw ' & $POP3Pass & ' -s ' & $POP3Server & ' -delete -xtract -port 110', '', @SW_HIDE)
    Sleep(1000)
    $file = FileFindFirstFile($source & '\*.pdf')
    If $file = -1 Then Return 1
    MsgBox(0, "test", "FileFindFirstFile Successful", 1)
    While 1
        $pdffile = FileFindNextFile($file)
        If @error Then ExitLoop
        RunWait('bfish.exe /I:"' & $source & '\' & $pdffile & '" /O:"' & $dest & '\' & $pdffile & '" /P:"' & $Blowfish_Password & '" /D /Q', "", @SW_HIDE)
        If FileExists($dest & '\' & $pdffile) Then
        ;File successfully decrypted, print it!
            FileChangeDir($GSPrintDir)
            RunWait('gsprint.exe "' & $dest & '\' & $pdffile & '"', $GSPrintDir, @SW_HIDE)
        EndIf
        FileDelete($source & '\' & $pdffile);delete the encrypted version
        FileDelete($source & '\*.txt')
        FileDelete($source & '\*.out')
    WEnd
    FileClose($file)
    MsgBox(0, "test", "GetMail function completed", 1)
    Return 1
EndFunc  ;==>GetMail
#endregion

#region SendMail Functions
Func SendMail()
    If Not FileExists($PDF_Dir & '\*.pdf') Then Return 1
    Dim $PDFfiles[1]
    
    $PDFHandle = FileFindFirstFile($PDF_Dir & '\*.pdf')
    While 1
        $file = FileFindNextFile($PDFHandle)
        If $file <> '' Then
            ReDim $PDFfiles[ (UBound($PDFfiles) + 1) ]
            $PDFfiles[0] += 1
            $PDFfiles[ (UBound($PDFfiles) - 1) ] = $file
        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)
        
        FileSend($PDF_Dir & '\Encrypted\' & $PDFfiles[$x])
        FileMove($PDF_Dir & '\' & $PDFfiles[$x], $PDF_Dir & '\Archives\' & $PDFfiles[$x])
        FileDelete($PDF_Dir & '\Encrypted\' & $PDFfiles[$x])
    Next
    Return 1
EndFunc  ;==>SendMail

Func FileSend($Attachment)
    
    $objMessage = ObjCreate('CDO.Message')
    With $objMessage
        .Subject = 'EUMatic.de File'
        .Sender = $Sender
        .From = $Sender
        .To = $Recipient
        .TextBody = ''
        .AddAttachment ($Attachment)
    EndWith
    With $objMessage.Configuration.Fields
        .Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $SMTPServer
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        .Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $SMTPUser
        .Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $SMTPPass
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
        .Update
    EndWith
    Return $objMessage.Send
EndFunc  ;==>FileSend
#endregion

While 1
    GetMail()
    Sleep(1000 * 5)
    $test = SendMail()
    MsgBox(0, 'test', $test)
WEnd

Writing AutoIt scripts since

_DateAdd("d", -2, _NowCalcDate())
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...