Sign in to follow this  
Followers 0
icu

_INetSmtpMail Errors [solved]

7 posts in this topic

#1 ·  Posted (edited)

Dear AutoIt Community,

I don't understand why when I use the code example for _INetSmtpMail in the AutoIt Help File I get Error code 50.

The Help File says:

5x - Cannot open SMTP session. x indicates the index number of last command issued to the SMTP server.

I've copied the example code nearly line by line below:

#include <INet.au3>
#include <Array.au3>

#cs The code example from the Help File
$s_SmtpServer = "mysmtpserver.com.au"
$s_FromName = "My Name"
$s_FromAddress = "From eMail Address"
$s_ToAddress = "To eMail Address"
$s_Subject = "My Test UDF"
Dim $as_Body[2]
$as_Body[0] = "Testing the new email udf"
$as_Body[1] = "Second Line"
$Response = _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body)
$err = @error
If $Response = 1 Then
    MsgBox(0, "Success!", "Mail sent")
Else
    MsgBox(0, "Error!", "Mail failed with error code " & $err)
EndIf
#ce

; my code

$s_SmtpServer = "saturn.meridian.local"
$s_FromName = "icu"
$s_FromAddress = "icu@workemail.com"
$s_ToAddress = "icu@personalemail.com"
$s_Subject = "My Test UDF"
Dim $as_Body[2]
$as_Body[0] = "Testing the new email udf"
$as_Body[1] = "Second Line"
$Response = _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body)
$err = @error
If $Response = 1 Then
    MsgBox(0, "Success!", "Mail sent")
Else
    MsgBox(0, "Error!", "Mail failed with error code " & $err)
EndIf

I've noticed that the help file didn't include <Array.au3> which I've added to my code but I still get the error... plus I think the 50 error relates to the server?

Any help would be greatly appreciated.

Kind regards,

icu

Edited by icu

Share this post


Link to post
Share on other sites



If you're using that exact code, I can understand why it's not working. You're using it with default settings instead of using a real mail server and username/password combination.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

hi icu ;),

Why not use Jos) instead? Its a bit more configurable and it supports secure SMTP too! :huh2:

Also, with respect to the #Include <Array.au3> line, its only needed when you use functions defined in that UDF. Working with arrays is native to AutoIt, look at this for example:

Local $aNames[4] = ["Billy", "John", "Amy", "Logan"]

Local $sOutput = "Contents of $aNames: " & @CR
For $i = 0 To UBound($aNames) - 1
    $sOutput &= "[" & $i & "]" & $aNames[$i] & @CR
Next

MsgBox(64, "Working with Arrays", $sOutput)

Good luck :alien:

-smartee

Share this post


Link to post
Share on other sites

@BrewManNH: Thanks for your reply. The function reference for _INetSmtpMail in the AutoIt Help File makes no reference to any "username/password combination" string. I know that if I just copy and paste the help file code snippet then my code won't work. However as you can see from my commented code lines, I know I should be using 'real' information in the following variables:

$s_SmtpServer = "saturn.meridian.local" ; is the real name of my work's mail server
$s_FromName = "icu" ; I substituted my handle in place of my real name which I put in my real code (I don't want my real name on the forum)
$s_FromAddress = "icu@workemail.com" ; I substituted a bogus work email in place of my real email (see above)
$s_ToAddress = "icu@personalemail.com" ; I substituted a bogus personal email in the place of my real email (see above)

It is because I used real variables in my code and the email didn't work that I asked for help on forum. I thought maybe I could be screwing up with not setting $s_helo and $s_first. I checked my work email account details in Outlook and I didn't see anything along those lines so I figured the code should just work.

@Smartee: Thanks for reply, array tip and function suggestion. I'll try out _INetSmtpMailCom() next time I'm at work and report back :-)

Share this post


Link to post
Share on other sites

Sorry about that, I didn't see that you had commented out the example code.

By the way, just a suggestion, if you use the [ autoit][ /autoit] code tags it will show your code with syntax highlighting. That's not a knock against you, just a suggestion.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Most SMTP-servers require authentication with username/password or smtp-after-pop. (Only servers who want to invite spammers do not ask for a password.)


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

The issue is now solved and it comes down to the email server settings at work. The is no authentication for our email server because it only works on our work network (and won't work with my home VPN to work's network).

The key to getting _INetSmtpMailCom() working for me was only running my AutoIt script at work and using the following variables:

$Username = ""
; password for the account used from where the mail gets sent - REQUIRED
$Password = ""
; port used for sending the mail
$IPPort = 25
; enables/disables secure socket layer sending - put to 1 if using httpS
$ssl = 0

As can be seen above I just had to leave the authentication variables null. For some reason I can't think of I put my work's network login details for the $Username and $Password variables and this was causing the errors.

Seems obvious now like most problems seen in hindsight.

Thanks again to everyone who replied, I really appreciate your time and effort.

-icu

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