judas Posted December 19, 2012 Share Posted December 19, 2012 I'm having some problem with the UDF _INetSmtpMailCom When I run the script, there's no problem, it works fine. But when I build the executable and run it, it throws an error: "The requested action with this object has failed." Here's the script I've tried on expandcollapse popup#include "C:\Program Files\AutoIt3\User Include\_INetSmtpMailCom.au3" mail_me() Func mail_me () Local $srand = Random(1000, 20000, 1) RunWait(@ScriptDir & "/7za.exe a archive" & $srand & ".7z *.jpg", @ScriptDir, @SW_HIDE) Local $SmtpServer = "smtp.mail.yahoo.com" Local $FromName = "baddy" Local $FromAddress = "user1@yahoo.com" Local $ToAddress = "user2@gmail.com" Local $body = "test" Local $Subject = "test attchment" Local $attchmnts = "" Local $BccAddress = "" Local $CcAddress = "" Local $imp = "Normal" Local $usernm = "user1@yahoo.com" Local $passw = "pahahaha" Local $port = 465 Local $ssl = 1 Local $search = FileFindFirstFile("*.7z") While 1 $temp = FileFindNextFile($search) & ";" If @error Then ExitLoop MsgBox(64, "", $attchmnts) $attchmnts &= $temp WEnd SetError(0) $attchmnts = StringTrimRight($attchmnts, 1) MsgBox(64, "", $attchmnts) _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $body, $attchmnts, $CcAddress, $BccAddress, $imp, $usernm, $passw, Number($port), 1) If @error Then MsgBox(0, "", "mail error") EndIf FileClose($search) ;#cs EndFunc The below one, while running the script, gives the same error with a little more information. The action that failed is $objEmail.Send. Now I dont know much about COM objects and stuffs. Hope somebody can clarify whats happening here. expandcollapse popup#include "C:\Program Files\AutoIt3\User Include\_INetSmtpMailCom.au3" ;#include <_INetSmtpMailCom.au3> #Include <File.au3> #Include <GuiEdit.au3> #include <GuiConstantsEx.au3> #include <UpdownConstants.au3> #include <WindowsConstants.au3> #Region Creating GUI GUICreate ( "Mailer 0.81", 415, 495 ) ;415,295 GUICtrlCreateLabel ( "SMTP Server*", 15, 18 ) GUICtrlCreateLabel ( "Name sender", 15, 18+25 ) GUICtrlCreateLabel ( "E-mail sender", 15, 18+25*2 ) GUICtrlCreateLabel ( "E-mail receiver*", 15, 18+25*3 ) GUICtrlCreateLabel ( "Subject", 15, 18+25*4 ) GUICtrlCreateLabel ( "Your message:", 230, 17 ) $Q1 = GUICtrlCreateLabel ( "?", 207, 18 ) $Q2 = GUICtrlCreateLabel ( "?", 207, 18+25 ) $Q3 = GUICtrlCreateLabel ( "?", 207, 18+25*2 ) $Q4 = GUICtrlCreateLabel ( "?", 207, 18+25*3 ) $Q5 = GUICtrlCreateLabel ( "?", 207, 18+25*4 ) $Q6 = GUICtrlCreateLabel ( "?", 372, 17 ) $Q7 = GUICtrlCreateLabel ( "?", 193, 167 ) $Q8 = GUICtrlCreateLabel ( "?", 371, 167 ) $ISMTP = GUICtrlCreateInput ( "", 100, 15, 100, 20, $ES_READONLY ) $INameSender = GUICtrlCreateInput ( "", 100, 15+25, 80, 20 ) $IEmailSender = GUICtrlCreateInput ( "", 100, 15+25*2, 80, 20 ) $IEmailReceiver = GUICtrlCreateInput ( "", 100, 15+25*3, 100, 20 ) $ISubject = GUICtrlCreateInput ( "", 100, 15+25*4, 80, 20 ) $IMessage = GUICtrlCreateEdit ( "", 230, 36, 170, 99, $ES_WANTRETURN + $ES_AUTOVSCROLL + $WS_VSCROLL ) GUICtrlCreateGroup ( "Account information", 15, 145, 380, 49 ) GUICtrlCreateLabel ( "Username*", 30, 167 ) GUICtrlCreateLabel ( "Password*", 210, 167 ) $AUsername = GUICtrlCreateInput ( "", 87, 164, 100 ) $APassword = GUICtrlCreateInput ( "", 265, 164, 100 ) GUICtrlCreateGroup ( "Priority", 15, 200, 200, 49 ) $PriorLow = GUICtrlCreateRadio ( "Low", 30, 217 ) $PriorNormal = GUICtrlCreateRadio ( "Normal", 88, 217 ) $PriorHigh = GUICtrlCreateRadio ( "High", 156, 217 ) $InfoLabel = GUICtrlCreateLabel ( "Fill in the required information and press send.", 15, 265, 300, 20, $ES_CENTER ) $Send = GUICtrlCreateButton ( "Send", 315, 260, 80, 25 ) $CNameSender = GUICtrlCreateCheckBox ( "", 185, 44, 20, 12 ) $CEmailSender = GUICtrlCreateCheckBox ( "", 185, 69, 20, 12 ) $CSubject = GUICtrlCreateCheckBox ( "", 185, 119, 20, 12 ) $CMessage = GUICtrlCreateCheckBox ( "", 385, 18, 20, 12 ) $FromNameDummy = GUICtrlCreateLabel ( "FromNameDummy", 10, 300 ) $FromAddressDummy = GUICtrlCreateLabel ( "FromAddressDummy", 200, 300 ) $SubjectDummy = GUICtrlCreateLabel ( "SubjectDummy", 10, 320 ) $MessageDummy = GUICtrlCreateLabel ( "MessageDummy", 10, 340, 395, 200 ) #EndRegion ;Fills GUICtrlSetData ( $ISMTP, "smtp.gmail.com" ) GUICtrlSetData ( $INameSender, "TestAccount" ) GUICtrlSetData ( $IEmailSender, "TestAccount@Test.nl" ) GUICtrlSetData ( $IEmailReceiver, "supercasje@gmail.com" ) GUICtrlSetData ( $ISubject, "The testsubject" ) GUICtrlSetData ( $IMessage, "Testing message," & @CRLF & @CRLF & "Made by Rawox" & @CRLF & "lol" ) GUICtrlSetData ( $AUsername, "***" ) GUICtrlSetData ( $APassword, "***" ) #Region Changes GUICtrlSetTip ( $Q1, "The SMTP Server is required to send emails through."& @CRLF & "Only Gmail (smtp.gmail.com) is working.", "SMTP Server (Required)", 1, 1 ) GUICtrlSetTip ( $Q2, "Use your own name or some else's to keep you unkown." & @CRLF & "Check the box to use random names.", "Name sender", 1, 1 ) GUICtrlSetTip ( $Q3, "Use your own email adrress or someone else's to keep you unknown." & @CRLF & "Check the box to use random email addresses.", "E-mail sender", 1, 1 ) GUICtrlSetTip ( $Q4, "The email address of the receiver, the emails will be send" & @CRLF & "to this email address so make sure it is correct", "E-mail receiver (Required)", 1, 1 ) GUICtrlSetTip ( $Q5, "The subject of the messages you are sending." & @CRLF & "Check the box to use random subjects.", "Subject", 1, 1 ) GUICtrlSetTip ( $Q6, "The body of the messages you are sending." & @CRLF & "Check the box to use random messages.", "Your message", 1, 1 ) GUICtrlSetTip ( $Q7, "The username of an existing email account." & @CRLF & "e.g. John, no full e-mail addresses like Jon@provider.net", "Username", 1, 1 ) GUICtrlSetTip ( $Q8, "The password that is used for the chosen email address." & @CRLF & "Your password will not be abused.", "Password", 1, 1 ) GUICtrlSetColor ( $Q1, 0xb0b0b0 ) GUICtrlSetColor ( $Q2, 0xb0b0b0 ) GUICtrlSetColor ( $Q3, 0xb0b0b0 ) GUICtrlSetColor ( $Q4, 0xb0b0b0 ) GUICtrlSetColor ( $Q5, 0xb0b0b0 ) GUICtrlSetColor ( $Q6, 0xb0b0b0 ) GUICtrlSetColor ( $Q7, 0xb0b0b0 ) GUICtrlSetColor ( $Q8, 0xb0b0b0 ) GUICtrlSetState ( $PriorNormal, $GUI_CHECKED ) GUISetState ( @SW_SHOW ) #EndRegion While 1 Switch GUIGetMsg() Case $Send $SmtpServer = GUICtrlRead ( $ISMTP ) ; address for the smtp-server to use - REQUIRED\ If GUICtrlRead ( $CNameSender ) = $GUI_CHECKED Then ; name from who the email was sent $Length = Random ( 5, 30, 1 ) GUICtrlSetData ( $FromNameDummy, CreateRandomString ( $Length ) ) $FromName = GUICtrlRead ( $FromNameDummy ) Else $FromName = GUICtrlRead ( $INameSender ) EndIf If GUICtrlRead ( $CEmailSender ) = $GUI_CHECKED Then ; address from where the mail should come $Length = Random ( 5, 30, 1 ) GUICtrlSetData ( $FromAddressDummy, CreateRandomString ( $Length ) ) $FromAddress = GUICtrlRead ( $FromAddressDummy ) Else $FromAddress = GUICtrlRead ( $INameSender ) EndIf $ToAddress = GUICtrlRead ( $IEmailReceiver ) ; destination address of the email - REQUIRED If GUICtrlRead ( $CSubject ) = $GUI_CHECKED Then ; subject from the email - can be anything you want it to be $Length = Random ( 5, 30, 1 ) GUICtrlSetData ( $SubjectDummy, CreateRandomString ( $Length ) ) $Subject = GUICtrlRead ( $SubjectDummy ) Else $Subject = GUICtrlRead ( $INameSender ) EndIf If GUICtrlRead ( $CMessage ) = $GUI_CHECKED Then ; the messagebody from the mail - can be left blank but then you get a blank mail $Length = Random ( 40, 320, 1 ) GUICtrlSetData ( $MessageDummy, CreateRandomString ( $Length / 15 ) & @CRLF & @CRLF & _ CreateRandomString ( $Length / 1.5 ) & @CRLF & @CRLF & _ CreateRandomString ( $Length * 2 ) & @CRLF & @CRLF & _ CreateRandomString ( $Length / 10 ) & @CRLF & _ CreateRandomString ( $Length / 20 ) & @CRLF ) $Body = GUICtrlRead ( $MessageDummy ) Else $Body = GUICtrlRead ( $INameSender ) EndIf $AttachFiles = "" ; the file you want to attach- leave blank if not needed $CcAddress = "" ; address for cc - leave blank if not needed $BccAddress = "" ; address for bcc - leave blank if not needed If GUICtrlRead ( $PriorLow ) = $GUI_CHECKED Then ; Send message priority: "High", "Normal", "Low" $Importance = "Low" ElseIf GUICtrlRead ( $PriorHigh ) = $GUI_CHECKED Then $Importance = "High" Else $Importance = "Normal" EndIf $Username = GUICtrlRead ( $AUsername ) ; username for the account used from where the mail gets sent - REQUIRED $Password = GUICtrlRead ( $APassword ) ; password for the account used from where the mail gets sent - REQUIRED $IPPort = 465 ; GMAIL port used for sending the mail $ssl = 1 ; enables/disables secure socket layer sending - put to 1 if using httpS ;~ $IPPort=25 ; NOT GMAIL port used for sending the mail ;~ $ssl=0 ; enables/disables secure socket layer sending - put to 1 if using httpS _INetSmtpMailCom ( $SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl ) Case $CNameSender If GUICtrlRead ( $CNameSender ) = $GUI_CHECKED Then GUICtrlSetState ( $INameSender+1, $GUI_FOCUS ) GUICtrlSetData ( $INameSender, "Random" ) GUICtrlSetState ( $INameSender, $GUI_DISABLE ) Else GUICtrlSetData ( $INameSender, "" ) GUICtrlSetState ( $INameSender, $GUI_ENABLE ) GUICtrlSetState ( $INameSender, $GUI_FOCUS ) EndIf Case $CEmailSender If GUICtrlRead ( $CEmailSender ) = $GUI_CHECKED Then GUICtrlSetState ( $IEmailSender+1, $GUI_FOCUS ) GUICtrlSetData ( $IEmailSender, "Random" ) GUICtrlSetState ( $IEmailSender, $GUI_DISABLE ) Else GUICtrlSetData ( $IEmailSender, "" ) GUICtrlSetState ( $IEmailSender, $GUI_ENABLE ) GUICtrlSetState ( $IEmailSender, $GUI_FOCUS ) EndIf Case $CSubject If GUICtrlRead ( $CSubject ) = $GUI_CHECKED Then GUICtrlSetState ( $ISubject+1, $GUI_FOCUS ) GUICtrlSetData ( $ISubject, "Random" ) GUICtrlSetState ( $ISubject, $GUI_DISABLE ) Else GUICtrlSetData ( $ISubject, "" ) GUICtrlSetState ( $ISubject, $GUI_ENABLE ) GUICtrlSetState ( $ISubject, $GUI_FOCUS ) EndIf Case $CMessage If GUICtrlRead ( $CMessage ) = $GUI_CHECKED Then GUICtrlSetState ( $IMessage+1, $GUI_FOCUS ) GUICtrlSetData ( $IMessage, "Random" ) GUICtrlSetState ( $IMessage, $GUI_DISABLE ) Else GUICtrlSetData ( $IMessage, "" ) GUICtrlSetState ( $IMessage, $GUI_ENABLE ) GUICtrlSetState ( $IMessage, $GUI_FOCUS ) EndIf Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func CreateRandomString ( $Length ) $RandomSN = Random ( 3, 14, 1 ) ; Spaces $j = 0 ; Spaces Local $Word = "" ; Base For $i = 1 to $Length ; Base $Word &= Chr ( Random ( 50, 127, 1 ) ) ; Base If $j = $RandomSN Then ; Spaces $Word &= " " ; Spaces $RandomSN = Random ( 3, 14,1 ) ; Spaces $j = 0 ; Spaces Else ; Spaces $j += 1 ; Spaces EndIf ; Spaces Next ; Base $FromName = $Word ; Base Return $FromName ; Base EndFunc Link to comment Share on other sites More sharing options...
judas Posted December 20, 2012 Author Share Posted December 20, 2012 Anybody? Some clues? The function is working well both while running as a script (the first one) and an executable. Problem is arising when its part of a bigger script and being called. I've checked all the variable names so there aren't any problems with unintended scopes. What could be going wrong..? Link to comment Share on other sites More sharing options...
Developers Jos Posted December 20, 2012 Developers Share Posted December 20, 2012 You need to add the COMERROR handler like shown in the example to get better information about what the error is. Are you sure that Yahoo uses the exact same setting for port and SSL as Gmail? Jos SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
judas Posted December 20, 2012 Author Share Posted December 20, 2012 C:Program FilesAutoIt3User Include_INetSmtpMailCom.au3 (96) : ==> The requested action with this object has failed.: $objEmail.Send $objEmail.Send^ ERROR Link to comment Share on other sites More sharing options...
Developers Jos Posted December 20, 2012 Developers Share Posted December 20, 2012 Again, Add the ComErrorHandler as shown in the example that I made. Jos SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
judas Posted December 20, 2012 Author Share Posted December 20, 2012 Oh, I dint get it ### COM Error ! Number: 80020009 ScriptLine: 97 Description:The transport failed to connect to the server. What I notice is, when it goes well, my firewall asks for a confirmation if I want to allow the connection. When it fails, there're no promts from the firewall. And more confusingly, its uncertain. Sometimes, the email is sucessfull, sometimes not; despite being the same mail :/ Link to comment Share on other sites More sharing options...
Developers Jos Posted December 20, 2012 Developers Share Posted December 20, 2012 Just tried it with my Yahoo account and was able to send many times successfully without any error. Jos SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
judas Posted December 21, 2012 Author Share Posted December 21, 2012 (edited) EDIT:: the problem appears to be with my Y! account. It was asking for entering a capcha (in browser). So I guess that was preventing it.Anyway, thanks for both your help and your UDF Its working fine with yahoo. But with the provided settings from gmail and hotmail, none are working. Could you test a bit?Hotmail:http://windows.microsoft.com/en-US/hotmail/send-receive-email-from-mail-clientgmail:Outgoing Mail (SMTP) Server - Requires TLSsmtp.gmail.comPort: 465 or 587Requires SSL: YesRequires authentication: YesUse same settings as incoming mail server-------------------------------------------------------------<no more needed>This is the file i'm including for your UDF.Is it alright?expandcollapse popup; ;################################## ; Include ;################################## #Include<file.au3> ;################################## ; Variables ;################################## #cs $SmtpServer = "MailServer" ; address for the smtp-server to use - REQUIRED $FromName = "Name" ; name from who the email was sent $FromAddress = "your@Email.Address.com" ; address from where the mail should come $ToAddress = "your@Email.Address.com" ; destination address of the email - REQUIRED $Subject = "Userinfo" ; subject from the email - can be anything you want it to be $Body = "" ; the messagebody from the mail - can be left blank but then you get a blank mail $AttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed $CcAddress = "CCadress1@test.com" ; address for cc - leave blank if not needed $BccAddress = "BCCadress1@test.com" ; address for bcc - leave blank if not needed $Importance = "Normal" ; Send message priority: "High", "Normal", "Low" $Username = "******" ; username for the account used from where the mail gets sent - REQUIRED $Password = "********" ; password for the account used from where the mail gets sent - REQUIRED $IPPort = 25 ; port used for sending the mail $ssl = 0 ; enables/disables secure socket layer sending - put to 1 if using httpS ;~ $IPPort=465 ; GMAIL port used for sending the mail ;~ $ssl=1 ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS ;################################## ; Script ;################################## #ce Global $oMyRet[2] Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") #cs $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl) If @error Then MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc) EndIf #ce ; ; The UDF Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $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 : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console If FileExists($S_Files2Attach[$x]) Then ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF) $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 If Number($IPPort) = 0 then $IPPort = 25 $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 ; Set Email Importance Switch $s_Importance Case "High" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High" Case "Normal" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal" Case "Low" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low" EndSwitch $objEmail.Fields.Update ; Sent the Message $objEmail.Send If @error Then SetError(2) Return $oMyRet[1] EndIf $objEmail="" 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 Edited December 21, 2012 by judas Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now