Sign in to follow this  
Followers 0
pshankland

A little help with _INetSmtpMail

14 posts in this topic

I have the following script which is simply meant to send an Email with the users current private IP address, but when I run it I keep getting an @error value of 0 returned:

#include <Inet.au3>

$PublicIP = _GetIP()
$PrivateIP = @IPAddress1
$SMTPServer = "192.168.1.1"
$FromName = @UserName
$FromAddress = $FromName & "@SOMEWHERE.COM"
$ToAddress = "SOMEONE@SOMEWHERE.COM"
$Subject = $FromName & "'s Private IP Address"
$Body = $FromName & "'s IP Address is: " & $PrivateIP
$Err = @error

$Response = _INetSmtpMail($SMTPServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body)
If $Response = 1 Then
    MsgBox(0, "Success", "Completed")
Else
    MsgBox(0, "Error", "Failed - Please contact whoever sent you this program" & @CRLF & "Error Code: " & $Err)
EndIf

As I said, I always get the error but with a value of 0. I have checked through the SMTP servers logs and this program isn't even getting as far as connecting.

Any suggestions?

Thanks.

Share this post


Link to post
Share on other sites



What happens when you try to connect to your mail server using Telnet? At the Command Prompt, type this:

telnet 192.168.1.1 25

Your mail server should respond in some way. If that isn't happening, then your mail server is not running on 192.168.1.1, or it's not working correctly.


[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post


Link to post
Share on other sites

When I telnet to the SMTP server it responds immediatly.

Any other suggestions?

Thanks.

Share this post


Link to post
Share on other sites

Have attached the response from a telnet connection to my SMTP server.

Does anyone know what might be wrong with the script I have written?

Thanks.

post-16707-1185471905_thumb.jpg

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Okay, it looks like you don't have any fundamental connectivity issues. I suspect that your mail server is expecting something from a mail sending connection that your system just isn't sending. Try typing this into your telnet session, and post the results here.

HELO
MAIL FROM: <your.address@domain.com>
RCPT TO: <target.address@domain.com>
DATA
From: Your Name <your.address@domain.com>
To: Target Name <target.address@domain.com>
Subject: Your Subject
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII


.

{this line inserted to indicate a carriage return after the period is required.}

You have to type all of the carriage returns as shown for it to work. This is exactly what the _INetSmtpMail script is doing, but this way you can see exactly what your mail server is doing with it.

Edited by lod3n

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post


Link to post
Share on other sites

Looking at the _INetSmtpMail function more closely, I see that it has a Trace option, which you can turn on to see the same information. Do that instead, it's much easier.


[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post


Link to post
Share on other sites

Do you have a software firewall that is restricting access to either the AutoIt3 executable or the compiled script? When I tried running a local mail server, my software firewall caught it even though it was connecting to the local computer.

Share this post


Link to post
Share on other sites

Have attached the telnet output. I received the Email at my inbox no problems.

Have no software firewall sitting in between my machine and the SMTP server and the server has no restrictions on accepting connections.

Haven't look at the trace option, but will take a look now.

Thanks for the help... keep it coming :)

post-16707-1185475678_thumb.jpg

Share this post


Link to post
Share on other sites

No clue on how to use the trace param within _INetSmtpMail, sorry.

Share this post


Link to post
Share on other sites

Attached is the output from trace.

Is there anything obviously wrong?

Thanks.

post-16707-1185537383_thumb.jpg

Share this post


Link to post
Share on other sites

Yes. There should be more there. Try the first thing I said, about typing the commands into the Telnet session.

I have done this already and posted the results here. In post 8 you will see the telnet session where I typed in exactly as you suggested.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Oops, sorry I must have missed that. Good that your SMTP server is working, but I am clueless why the function behaves as it does. Here's another approach. This function should work in place of the one you are using, but it uses COM instead.

Func _CDOSendMail($SMTPServer, $FromAddress, $ToAddress, $Subject, $Body, $attachment="")
    $objEmail = ObjCreate("CDO.Message")
    
    $objEmail.From = $from
    $objEmail.To = $to
    $objEmail.Subject = $subject
    
    ;$objEmail.HTMLBody = $body
    $objEmail.Textbody = $body
    
    if $attachment <> "" then
        if fileexists($attachment) Then
            $objEmail.AddAttachment($attachment)
        EndIf
    EndIf
    
    $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 ;cdoSendUsingPort
    $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $SMTPServer
    $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
    $objEmail.Configuration.Fields.Update
    
    $objEmail.Send
    if @error then
        ConsoleWrite("Email send error!" & @crlf)
        ;should do something else too... maybe a netmessage?
    EndIf
EndFunc
Edited by lod3n

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

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