Sign in to follow this  
Followers 0
Dryden

Help! Sending Multiple Emails

16 posts in this topic

#1 ·  Posted (edited)

Hi m8s!

I have a problem.

I'm using this basic email sender inside my script:

Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Username = "", $s_Password = "")
    $objEmail = ObjCreate("CDO.Message")
    $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
    $objEmail.To = $s_ToAddress
    Local $i_Error = 0
    Local $i_Error_desciption = ""
    If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
    If $s_BccAddress <> "" Then $objEmail.Cc = $s_BccAddress
    $objEmail.Subject = $s_Subject
    If StringInStr($as_Body,"<") and StringInStr($as_Body,">") Then
        $objEmail.HTMLBody = $as_Body
    Else
        $objEmail.Textbody = $as_Body & @CRLF
    EndIf
    If $s_AttachFiles <> "" Then
        Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
        For $x = 1 To $S_Files2Attach[0]
            $S_Files2Attach[$x] = _PathFull ($S_Files2Attach[$x])
            If FileExists($S_Files2Attach[$x]) Then
                $objEmail.AddAttachment ($S_Files2Attach[$x])
            Else
                $i_Error_desciption = $i_Error_desciption & @lf & 'File not found to attach: ' & $S_Files2Attach[$x]
                SetError(1)
                return 0
            EndIf
        Next
    EndIf
    
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
;Authenticated SMTP
    If $s_Username <> "" Then
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
    EndIf
;Update settings
    $objEmail.Configuration.Fields.Update
; Sent the Message
    $objEmail.Send
    if @error then
        SetError(2)
        return $oMyRet[1]
    EndIf
EndFunc;==>_INetSmtpMailCom

The problem is I can only send one email, I have a gui that alows the user to send it again, but It only sends the 1st time, the 2nd time I try to send the script crashes with this error:

$objEmail.Send

$objEmail.Send^ ERROR

Please help!! Edited by Dryden

"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

Share this post


Link to post
Share on other sites



When you are doing the multiple sending are you just recalling the function?


[sub]Quantum mechanics: The dreams stuff is made of[/sub]

Share this post


Link to post
Share on other sites

yes. I change a couple of things and then call the function again. But even If I don't change anything, if I call the function again to send the same mail from the same address and to the same recipient, I get the same error as well...


"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

Share this post


Link to post
Share on other sites

$objEmail.Send^ ERROR

Does it say anything before or after in the output window?


[sub]Quantum mechanics: The dreams stuff is made of[/sub]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Does it say anything before or after in the output window?

I don't have an output window.

The program works this way: I have some buttons and one of them is the "send" button. when you press it, it grays out all the buttons and sends the mail. after the send is done, the buttons return, and the program is ready to go again.

The problem is that when I send it the 2nd time the program always crashes, and If I run it in SciTE, I get that error in the console ($objEmail.Send^ ERROR)...

Edited by Dryden

"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

Share this post


Link to post
Share on other sites

anyone?


"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

please...

If i close the program and reopen it, I can send the email again, so I was wondering, nobody can solve my problem, so I was thinking... Is there a way to compile the sender on it's own .exe and then call it from the main application giving it the appropriate parameters?

Edited by Dryden

"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

u mean add this: ?

; Com Error Handler
Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    $oMyRet[0] = $HexNumber
    $oMyRet[1] = StringStripWS($oMyError.description,3)
    ConsoleWrite("### COM Error !  Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:" & $oMyRet[1] & @LF)
    SetError(1); something to check for when this function returns
    Return
EndFunc;==>MyErrFunc

ok, i'll try it. thx

Edited by Dryden

"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

Share this post


Link to post
Share on other sites

josh I did what you said, the error I get is:

Error code: 2 RC: The transport failed to connect to the server.

and no matter how long I wait, If I don't close the program I can't send more than one mail...

"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

Share this post


Link to post
Share on other sites

bump


"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

Share this post


Link to post
Share on other sites

please. someone?!


"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

Share this post


Link to post
Share on other sites

Just tried this script and it worked fine for me:

;##################################
; Include
;##################################
#include<file.au3>
#include<inet.au3>
;
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
;
$rc = _INetSmtpMailCom("Mail.myprovidersmailserver.nl", "Jos", "MYemailaddress2@myprovidersmailserver.nl", "MYemailaddress1@domain.nl,MYemailaddress2@domain.nl", "Test Subject1", "Test <b>Body</b>")
$rc = _INetSmtpMailCom("Mail.myprovidersmailserver.nl", "Jos", "MYemailaddress2@myprovidersmailserver.nl", "MYemailaddress1@domain.nl,MYemailaddress2@domain.nl", "Test Subject2", "Test1 <b>Body</b>")
$rc = _INetSmtpMailCom("Mail.myprovidersmailserver.nl", "Jos", "MYemailaddress2@myprovidersmailserver.nl", "MYemailaddress1@domain.nl,MYemailaddress2@domain.nl", "Test Subject3", "Test2 <b>Body</b>")
$rc = _INetSmtpMailCom("Mail.myprovidersmailserver.nl", "Jos", "MYemailaddress2@myprovidersmailserver.nl", "MYemailaddress1@domain.nl,MYemailaddress2@domain.nl", "Test Subject4", "Test3 <b>Body</b>")
$rc = _INetSmtpMailCom("Mail.myprovidersmailserver.nl", "Jos", "MYemailaddress2@myprovidersmailserver.nl", "MYemailaddress1@domain.nl,MYemailaddress2@domain.nl", "Test Subject5", "Test4 <b>Body</b>")
Exit
;
;
Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
    Local $objEmail = ObjCreate("CDO.Message")
    $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
    $objEmail.To = $s_ToAddress
    Local $i_Error = 0
    Local $i_Error_desciption = ""
    If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
    If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
    $objEmail.Subject = $s_Subject
    If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then
        $objEmail.HTMLBody = $as_Body
    Else
        $objEmail.Textbody = $as_Body & @CRLF
    EndIf
    If $s_AttachFiles <> "" Then
        Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
        For $x = 1 To $S_Files2Attach[0]
            $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])
            ConsoleWrite('@@ Debug(62) : $S_Files2Attach = ' & $S_Files2Attach & @LF & '>Error code: ' & @error & @LF);### Debug Console
            If FileExists($S_Files2Attach[$x]) Then
                $objEmail.AddAttachment ($S_Files2Attach[$x])
            Else
                ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
                SetError(1)
                Return 0
            EndIf
        Next
    EndIf
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
;Authenticated SMTP
    If $s_Username <> "" Then
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
    EndIf
    If $ssl Then
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    EndIf
;Update settings
    $objEmail.Configuration.Fields.Update
; Sent the Message
    $objEmail.Send
    If @error Then
        SetError(2)
        Return $oMyRet[1]
    EndIf
EndFunc  ;==>_INetSmtpMailCom
;
;
; Com Error Handler
Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    $oMyRet[0] = $HexNumber
    $oMyRet[1] = StringStripWS($oMyError.description, 3)
    ConsoleWrite("### COM Error !  Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:" & $oMyRet[1] & @LF)
    SetError(1); something to check for when this function returns
    Return
EndFunc  ;==>MyErrFunc

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Just tried this script and it worked fine for me:

It works fine for me too, but it works only once... Try making it loop 2 times in order to send 2 emails.

"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

Share this post


Link to post
Share on other sites

It works fine for me too, but it works only once... Try making it loop 2 times in order to send 2 emails.

:) ... this example sends 5 messages separately.... so where are you trying to loop ?

:)


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

:) ... this example sends 5 messages separately.... so where are you trying to loop ?

:)

Sorry, didn't notice that... I tried your script as you pasted it, changing the server and username and whatnot... I made it send 4 times, I get only 1 e-mail and this in the scyte console:
### COM Error !  Number: 80020009   ScriptLine: 60   Description:The transport failed to connect to the server.
### COM Error !  Number: 80020009   ScriptLine: 60   Description:The transport failed to connect to the server.
### COM Error !  Number: 80020009   ScriptLine: 60   Description:The transport failed to connect to the server.

"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

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