Jump to content
Sign in to follow this  

INetSMTPMail not working in latest Autoit

Recommended Posts


I have been using Auotit to send status emails from a variety of systems (external to my work using gmail) including my work desktop PC (using company email gateway) - sending emails addressed to me and from me.

A few days ago I upgraded to the latest version of Autoit ( and I cannot send emails from my PC using INetSMTPmail through our mail gateway.

To test this I grabbed a script that worked on a PC running a previous version of Autoit and that worked fine from the other PC which has an earlier version of Autoit on it. I had the source code for that and an exe so copied them to my PC and run the exe code which worked fine (sent me the status email). I then opened the source code in the SciTE editor and ran it, the script runs fine but doesn't send the email. I added some code to print out the error and I got 

"Mail failed with error code 1"

checking the help file there is no explanation for Error Code 1.

Running my new scripts I get the error

"Mail failed with error code 50"

I don't understand why I get two different error codes - or why in the latest version it fails.

Any help gratefully appreciated.

I guess I could copy the script to the PC with the earlier version of Autoit and compile it and see what happens.


Share this post

Link to post
Share on other sites

@GeorgeP, welcome to the AutoIt forum.

the latest version is, not as you mentioned. please update and test again.

if the problem persists, remember that _INetSMPTMail() is not a core function, it's a UDF - meaning, the source is available for you to read, understand and troubleshoot (it is in the file "Inet.au3" in the AutoIt "Include" folder, typically "C:\Program Files (x86)\AutoIt3\Include"). for example, the very first line validates the parameters and may return @error 1.



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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By wysocki
      I have a smartphone and I use it to access my email. However, when composing an email on it I have a problem. My list of phone contacts on the phone is very different from my list of email contacts in my Thunderbird desktop app.  I use my Gmail address book to store primarily phone contacts, and I use Thunderbird for my list of email contacts. I wanted a way to get my Thunderbird contact list onto my smartphone to be able to compose emails to addresses in that list. Here's my solution.
      I wrote a script to export my Thunderbird Personal Address Book to a csv file. It then reads that file and re-writes it with html wrappers around the data to make it into a nicely formatted web page. It then uploads the htm file to my website. On my smartphone, I created a shortcut to the file's URL and whenever I click it, I get the list displayed. Each contact shows name and email address along with a COPY button that will put the address into the clipboard. Then in my email client, I can easily paste that address into it. Alternatively, clicking on the actual email link will open a new message dialog in your email client with that address already entered.
      To use the app, all you need to do is use Thunderbird and have a webserver available. You'll need to download the FTPEX.AU3 file from this website and make a few changes to some constants around line 17 for FTP login info, etc.
    • By nooneclose
      Good morning everyone, I thought I had already solved this issue but it turns out I did not. 
      My code finds unread emails with this specific subject line of "request" but when I change the subject to SKIPPED + "request" = ("SKIPPED request") the program still finds the email and tries to process it. I only want to process emails with the exact match subject of "request".
      Here is my code that "finds" the unread emails with the subject of "request" or so I thought. 
      Func ListUnreadEmails() ;******************************************************************************* ; Lists all unread E-mails from the folder Outlook-UDF-Test ;******************************************************************************* ; Stores all the unRead emails into an array Global $aItems = _OL_ItemFind($oOutlook, "*\Outlook-UDF-Test", $olMail, _ "[UnRead]=True", "Subject", "request", "EntryID,Subject", "", 1) ; Displays the array of unRead emails If IsArray($aItems) Then ;_ArrayDisplay($aItems, "OutlookEX UDF: _OL_ItemFind - Unread mails") Else MsgBox(48, "OutlookEX UDF: _OL_ItemFind Example Script", _ "Could not find an unread mail. @error = " & @error & ", @extended: " & @extended) EndIf ; Gets the number of unread emails Global $numberOfUnRead = UBound($aItems, $UBOUND_ROWS) - 1 ;MsgBox("", "Number of Unread emails", $numberOfUnRead) EndFunc It acts as if any part of the subject containing the word "request" and the email is unread that it will try to process it. (I think)
    • By nooneclose
      Good afternoon, I am in need of some help. I am sure this is a stupid question requiring only one or two lines of code. However, I would greatly appreciate the help I cannot figure this out. I also tried searching for the answer on the internet but no one except me apparently seems to be having a hard time figuring this out and or is asking about it. 
      I simply want to change the "status" of an email from unread to read once I have processed it. My code is over 500 lines and I would like not to clutter this post with it. Assume I have all my includes and connections properly defined and stuff. 
      Here is the bit of code where I am trying to change the email that was used from unread to read:
      Func ChangeEmailStatus() ;******************************************************************************* ; changes the status of an email from unread to Read ;******************************************************************************* Local $iRows = UBound($aItems, $UBOUND_ROWS) MsgBox("", "Number of Unread emails (Before Change)", $iRows) _OL_ItemModify($oOutlook,$aItems[$i][0], Default, "Read=True") MsgBox("", "Array Display 1", $aItems[1][0]) MsgBox("", "Array Display 2", $aItems[2][0]) Local $iRows = UBound($aItems, $UBOUND_ROWS) MsgBox("", "Number of Unread emails (After Change)", $iRows) EndFunc  
    • By azkirak
      Hi all,
      Trying to test sending an email using the _INetSmtpMail function, but I cannot get it to work.
      #include <Inet.au3> #include <MsgBoxConstants.au3> Local $s_SmtpServer = "smtp.gmail.com" Local $s_FromName = "My Name" Local $s_FromAddress = "x@gmail.com" Local $s_ToAddress = "x@gmail.com" Local $s_Subject = "Test - subject line" Local $as_Body[2] $as_Body[0] = "Test" $as_Body[1] = "End of test" Local $iResponse = _INetSmtpMail($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body) Local $iErr = @error If $iResponse = 1 Then     MsgBox($MB_SYSTEMMODAL, "Success!", "Mail sent") Else     MsgBox($MB_SYSTEMMODAL, "Error!", "Mail failed with error code " & $iErr) EndIf  
      "Mail failed with error code 50" is the message I receive.  I've looked at what the autoit help page says: 50x - Cannot send body. x indicates the line number of $aBody (first line is 0). 
      I cannot find any solution online that has fixed this issue.  Any guidance would be much appreciated!
    • By mattsk42
      I have a script that pops up a window, lets you type things in, and then emails our helpdesk. It works. What I want to do is add 3 more buttons that allow you to attach 3 photos (or less) from your computer. Something simple as "Add attachment" and then you can browse for it. I don't even know where to begin with programming that button. If anyone could post an example, that would be great.
      Here's the current script (changed to pet.com because I like dogs):
      ;expand popup ;#include <File.au3> ; =============================================================================================================================== ; Variables for the _INetSmtpMailCom ; =============================================================================================================================== Global Enum _ $g__INetSmtpMailCom_ERROR_FileNotFound = 1, _ $g__INetSmtpMailCom_ERROR_Send, _ $g__INetSmtpMailCom_ERROR_ObjectCreation, _ $g__INetSmtpMailCom_ERROR_COUNTER Global Const $g__cdoSendUsingPickup = 1 ; Send message using the local SMTP service pickup directory. Global Const $g__cdoSendUsingPort = 2 ; Send the message using the network (SMTP over the network). Must use this to use Delivery Notification Global Const $g__cdoAnonymous = 0 ; Do not authenticate Global Const $g__cdoBasic = 1 ; basic (clear-text) authentication Global Const $g__cdoNTLM = 2 ; NTLM Global $gs_thoussep = "." Global $gs_decsep = "," Global $sFileOpenDialog = "" ; Delivery Status Notifications Global Const $g__cdoDSNDefault = 0 ; None Global Const $g__cdoDSNNever = 1 ; None Global Const $g__cdoDSNFailure = 2 ; Failure Global Const $g__cdoDSNSuccess = 4 ; Success Global Const $g__cdoDSNDelay = 8 ; Delay #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> ; This is to get the local username Local $myVar = "USERNAME" Local $myValue = EnvGet($myVar) ; This is the GUI #Region ### START Koda GUI section ### Form=f:\scripts\autoit\name-issue.kxf $Form1 = GUICreate("Submit a Helpdesk Ticket", 371, 260, 214, 199) ;~ $Pet = GUICtrlCreateLabel("Pet username:", 8, 8, 79, 17) $Label2 = GUICtrlCreateLabel("Issue with as much detail as possible:", 8, 7, 180, 17) ;~ $Name = GUICtrlCreateInput("", 88, 5, 105, 21) $Issue = GUICtrlCreateEdit("", 8, 25, 353, 200) $Submit = GUICtrlCreateButton("Submit", 8, 230, 75, 25) $Cancel = GUICtrlCreateButton("Cancel", 92, 230, 75, 25) ;~ $Label1 = GUICtrlCreateLabel("(example: jconnor)", 92, 26, 98, 17) ;~ $Label3 = GUICtrlCreateLabel("@pet.com", 195, 8, 60, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### ; These are for future use ;~ $ClientName = "ClientName##" ;~ $AtPet = "@pet.com##" While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $Submit ; Execute code when user presses the button Local $sSmtpServer = "smtp.gmail.com" ; address for the smtp-server to use - REQUIRED Local $sFromName = "" ; name from who the email was sent Local $sFromAddress = "user@pet.com"; address from where the mail should come Local $sToAddress = "helpdesk@pet.com" ; destination address of the email - REQUIRED Local $sSubject = StringUpper ($myValue); subject from the email - can be anything you want it to be Local $sBody = GUICtrlRead($Issue); the messagebody from the mail - can be left blank but then you get a blank mail Local $sAttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed Local $sCcAddress = "" ; address for cc - leave blank if not needed Local $sBccAddress = "" ; address for bcc - leave blank if not needed Local $sImportance = "Normal" ; Send message priority: "High", "Normal", "Low" Local $sUsername = "jconnor@pet.com" ; username for the account used from where the mail gets sent - REQUIRED Local $sPassword = "ajlkdjfawyfbna" ; password for the account used from where the mail gets sent - REQUIRED Local $iIPPort = 465 ; GMAIL port used for sending the mail Local $bSSL = True ; GMAIL enables/disables secure socket layer sending - set to True if using httpS Local $bIsHTMLBody = False Local $iDSNOptions = $g__cdoDSNDefault Local $rc = _INetSmtpMailCom($sSmtpServer, $sFromName, $sFromAddress, $sToAddress, $sSubject, $sBody, $sAttachFiles, $sCcAddress, $sBccAddress, $sImportance, $sUsername, $sPassword, $iIPPort, $bSSL, $bIsHTMLBody, $iDSNOptions) If @error Then MsgBox(0, "_INetSmtpMailCom(): Error sending message", _ "Error code: " & @error & @CRLF & @CRLF & _ "Error Hex Number: " & _INetSmtpMailCom_ErrHexNumber() & @CRLF & @CRLF & _ "Description: " & _INetSmtpMailCom_ErrDescription() & @CRLF & @CRLF & _ "Description (rc): " & $rc & @CRLF & @CRLF & _ "ScriptLine: " & _INetSmtpMailCom_ErrScriptLine() _ ) ConsoleWrite("### COM Error ! Number: " & _INetSmtpMailCom_ErrHexNumber() & " ScriptLine: " & _INetSmtpMailCom_ErrScriptLine() & " Description:" & _INetSmtpMailCom_ErrDescription() & @LF) Else Func _Sendmail() Dim $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox(262208, "Success!", "Thank you.", 5) EndIf EndFunc ;==>_Enviarmail #Region UDF Functions ; The UDF ; #FUNCTION# ==================================================================================================================== ; Name ..........: _INetSmtpMailCom ; Description ...: ; Syntax ........: _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[, $bSSL = False[, $bIsHTMLBody = False[, $iDSNOptions = $g__cdoDSNDefault]]]]]]]]]]]]) ; Parameters ....: $s_SmtpServer - A string value. ; $s_FromName - A string value. ; $s_FromAddress - A string value. ; $s_ToAddress - A string value. ; $s_Subject - [optional] A string value. Default is "". ; $s_Body - [optional] A string value. Default is "". ; $s_AttachFiles - [optional] A string value. Default is "". ; $s_CcAddress - [optional] A string value. Default is "". ; $s_BccAddress - [optional] A string value. Default is "". ; $s_Importance - [optional] A string value. Default is "Normal". ; $s_Username - [optional] A string value. Default is "". ; $s_Password - [optional] A string value. Default is "". ; $IPPort - [optional] An integer value. Default is 25. ; $bSSL - [optional] A binary value. Default is False. ; $bIsHTMLBody - [optional] A binary value. Default is False. ; $iDSNOptions - [optional] An integer value. Default is $g__cdoDSNDefault. ; Return values .: None ; Author ........: Jos ; Modified ......: mLipok ; Remarks .......: ; Related .......: http://www.autoitscript.com/forum/topic/23860-smtp-mailer-that-supports-html-and-attachments/ ; Link ..........: http://www.autoitscript.com/forum/topic/167292-smtp-mailer-udf/ ; Example .......: Yes ; =============================================================================================================================== Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $s_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance = "Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $bSSL = False, $bIsHTMLBody = False, $iDSNOptions = $g__cdoDSNDefault) ; init Error Handler _INetSmtpMailCom_ErrObjInit() Local $objEmail = ObjCreate("CDO.Message") If Not IsObj($objEmail) Then Return SetError($g__INetSmtpMailCom_ERROR_ObjectCreation, Dec(_INetSmtpMailCom_ErrHexNumber()), _INetSmtpMailCom_ErrDescription()) ; Clear previous Err information _INetSmtpMailCom_ErrHexNumber(0) _INetSmtpMailCom_ErrDescription('') _INetSmtpMailCom_ErrScriptLine('') $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>' $objEmail.To = $s_ToAddress If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress $objEmail.Subject = $s_Subject ; Select whether or not the content is sent as plain text or HTM If $bIsHTMLBody Then $objEmail.Textbody = $s_Body & @CRLF Else $objEmail.HTMLBody = $s_Body EndIf ; Add Attachments 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 ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF) $objEmail.AddAttachment($S_Files2Attach[$x]) Else ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF) Return SetError($g__INetSmtpMailCom_ERROR_FileNotFound, 0, 0) EndIf Next EndIf ; Set Email Configuration $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = $g__cdoSendUsingPort $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") = $g__cdoBasic $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 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = $bSSL ;Update Configuration 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 ; Set DSN options If $iDSNOptions <> $g__cdoDSNDefault And $iDSNOptions <> $g__cdoDSNNever Then $objEmail.DSNOptions = $iDSNOptions $objEmail.Fields.Item("urn:schemas:mailheader:disposition-notification-to") = $s_FromAddress ;~ $objEmail.Fields.Item("urn:schemas:mailheader:return-receipt-to") = $s_FromAddress EndIf ; Update Importance and Options fields $objEmail.Fields.Update ; Sent the Message $objEmail.Send If @error Then _INetSmtpMailCom_ErrObjCleanUp() Return SetError($g__INetSmtpMailCom_ERROR_Send, Dec(_INetSmtpMailCom_ErrHexNumber()), _INetSmtpMailCom_ErrDescription()) EndIf ; CleanUp $objEmail = "" _INetSmtpMailCom_ErrObjCleanUp() EndFunc ;==>_INetSmtpMailCom ; ; Com Error Handler Func _INetSmtpMailCom_ErrObjInit($bParam = Default) Local Static $oINetSmtpMailCom_Error = Default If $bParam == 'CleanUp' And $oINetSmtpMailCom_Error <> Default Then $oINetSmtpMailCom_Error = '' Return $oINetSmtpMailCom_Error EndIf If $oINetSmtpMailCom_Error = Default Then $oINetSmtpMailCom_Error = ObjEvent("AutoIt.Error", "_INetSmtpMailCom_ErrFunc") EndIf Return $oINetSmtpMailCom_Error EndFunc ;==>_INetSmtpMailCom_ErrObjInit Func _INetSmtpMailCom_ErrObjCleanUp() _INetSmtpMailCom_ErrObjInit('CleanUp') EndFunc ;==>_INetSmtpMailCom_ErrObjCleanUp Func _INetSmtpMailCom_ErrHexNumber($vData = Default) Local Static $vReturn = 0 If $vData <> Default Then $vReturn = $vData Return $vReturn EndFunc ;==>_INetSmtpMailCom_ErrHexNumber Func _INetSmtpMailCom_ErrDescription($sData = Default) Local Static $sReturn = '' If $sData <> Default Then $sReturn = $sData Return $sReturn EndFunc ;==>_INetSmtpMailCom_ErrDescription Func _INetSmtpMailCom_ErrScriptLine($iData = Default) Local Static $iReturn = '' If $iData <> Default Then $iReturn = $iData Return $iReturn EndFunc ;==>_INetSmtpMailCom_ErrScriptLine Func _INetSmtpMailCom_ErrFunc() _INetSmtpMailCom_ErrObjInit() _INetSmtpMailCom_ErrHexNumber(Hex(_INetSmtpMailCom_ErrObjInit().number, 8)) _INetSmtpMailCom_ErrDescription(StringStripWS(_INetSmtpMailCom_ErrObjInit().description, 3)) _INetSmtpMailCom_ErrScriptLine(_INetSmtpMailCom_ErrObjInit().ScriptLine) SetError(1) ; something to check for when this function returns Return EndFunc ;==>_INetSmtpMailCom_ErrFunc #EndRegion UDF Functions _Sendmail() Exit Case $Cancel Exit EndSwitch WEnd  
  • Create New...