Jump to content

A little help with _INetSmtpMail


Recommended Posts

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.

Link to comment
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]

Link to comment
Share on other sites

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]

Link to comment
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

Link to comment
Share on other sites

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]

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...