Jump to content

Send email error - _INetSmtpMailCom error 2


AutID
 Share

Recommended Posts

As the tittle says I have an error using Jos' function.

I am trying to send an email from Hotmail server(smtp.live.com) to another Hotmail account.
 

My error is this: ### COM Error !  Number: 80020009   ScriptLine: 92   Description:The transport failed to connect to the server.
My code is not different from that in the UDF but I will post it

;
;##################################
; Include
;##################################
#Include<file.au3>
;##################################
; Variables
;##################################
$SmtpServer = "smtp.live.com"              ; address for the smtp-server to use - REQUIRED
$FromName = "Maria"                      ; name from who the email was sent
$FromAddress = "fromemail@hotmail.com" ; address from where the mail should come
$ToAddress = "toemail@hotmail.com"   ; destination address of the email - REQUIRED
$Subject = "Test email"                   ; subject from the email - can be anything you want it to be
$Body = "hi"                              ; the messagebody from the mail - can be left blank but then you get a blank mail
$AttachFiles = ""                       ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed
$CcAddress = ""       ; address for cc - leave blank if not needed
$BccAddress = ""     ; address for bcc - leave blank if not needed
$Importance = "Normal"                  ; Send message priority: "High", "Normal", "Low"
$Username = "********"                    ; username for the account used from where the mail gets sent - REQUIRED
$Password = "******"                  ; password for the account used from where the mail gets sent - REQUIRED
$IPPort = 25                            ; port used for sending the mail
$ssl = 0                                ; enables/disables secure socket layer sending - put to 1 if using httpS
;~ $IPPort=465                          ; GMAIL port used for sending the mail
;~ $ssl=1                               ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS
;##################################
; Script
;##################################
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
$rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
If @error Then
    MsgBox(0, "Error sending message", "Error code:" & @error & "  Description:" & $rc)
EndIf
;
; The UDF
Func _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, $ssl = 0)
    Local $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])
;~          ConsoleWrite('@@ Debug : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console
            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)
                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
    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") = 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
    ; 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
    $objEmail.Fields.Update
    ; Sent the Message
    $objEmail.Send
    If @error Then
        SetError(2)
        Return $oMyRet[1]
    EndIf
    $objEmail=""
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

P.S.   au3check will throw an error to the .To separator on the stable version. You will need to update to beta version.

 

Edit: I tried turning off firewall, unblocking port 25 but not a solution was given

Edited by AutID
Link to comment
Share on other sites

  • Developers

Doubt you are allowed to use port 25 without ssl for live.com mail.
The au3check error is fixed in the beta version.

>Found this example.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Doubt you are allowed to use port 25 without ssl for live.com mail.

The au3check error is fixed in the beta version.

>Found this example.

Jos

My bad for ssl disabled. Mistake on paste of the code.

I searched before posting here and found that post as well. Still I didn't come up with a solution.

I found out that my internet service providers may be blocking port 25. And all emails that are sent via internet are routed through the port 25 as far as I know.

Is there any solution about this besides asking them to unblock it?

Edited by AutID
Link to comment
Share on other sites

Use SSL and port 587 instead of 25.

Edit: In case it fails on port 587 too, use 465 instead, always with SSL activated.

Each server has a port and says if ssl must be enabled or not. I will not be experimenting with this, there is no point. smtp.live.com uses port 25 as far as I know according to Microsoft.

I am glad it works for you but it will not work for me. Read a bit better in which cases that function would work ;)

Edit: I talked with my ISP and they said that they are not blocking the port 25. However to ensure this they told me to reset the router to it's manufacture settings where the port 25 is not blocked. I did it. And the problem still remains.

Any other ideas?

I am seeing from the cmd that port 25 is not listening...

Edited by AutID
Link to comment
Share on other sites

Each server has a port and says if ssl must be enabled or not. I will not be experimenting with this, there is no point. smtp.live.com uses port 25 as far as I know according to Microsoft.

 

I just created an account in outlook.com to test it and it is working fine for me using port 25 and SSL enabled but I'm not using smtp.live.com, according to Microsoft doc it should be smtp-mail.outlook.com and as I said it is working fine.

Cheers,

sahsanu

Link to comment
Share on other sites

  • Developers

The Listening happens at the receiving side so why would you want to enable that?

Just try to telnet to the target server with port 25 and see what happens.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

The Listening happens at the receiving side so why would you want to enable that?

Just try to telnet to the target server with port 25 and see what happens.

I already tried. It says that the connection failed at port 23.

"...Could not open connection to the host, on port 23: Connect failed"

Edited by AutID
Link to comment
Share on other sites

guess you missed the word exact in my question. ;)

I didn't but I didn't want to share it because its our server.

siteground219.com is a first random I tried.

The messages changes. Sometimes it says that connection failed at port 23 sometimes at port 25.

http://www.who.is/nameserver/ns2.siteground219.com/

 

Edited by AutID
Link to comment
Share on other sites

  • Developers

Ok, so it isnt about hotmail but another server for your company?

Are you sure your company's mail server supports smtp directly at all?

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Ok, so it isnt about hotmail but another server for your company?

Are you sure your company's mail server supports smtp directly at all?

It is about Hotmail. I will be sending emails to our colleges. To their personal emails. I just used telnet to our server because I know it supports smtp directly. And of course I also tested other servers as I already told you.

Your function works on other connections as the other people who tested confirm in the thread.

Tested some other random servers today and I am still getting this message: "...Could not open connection to the host, on port 25: Connect failed"

Link to comment
Share on other sites

When you send mail first you have to determine which mail server is responsible for accepting email messages in behalf of the domain. Sometimes (often) it differs from the e.g. http server address.

This data is called MX record in the DNS. One of my very first AutoIt scripts was about getting MX record for the domain. Search the examples forum for something like that.

When you collect MX record, you pick one and fed your function with it (first arg).

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

As far as I am understanding that would be useful in case I am sending emails to servers. I tested the script and it is very good. I like it because it doesn't use any external tools to get the informations.
However this is not my case here.

Let me clear this out for everyone. I just tested a server because @Jos asked me to give him the results of telnet. Nothing else. As I am saying above I will be sending mails to our colleges, to their personal email addresses.
So it could be at their home, their job, public places, anywhere. Not to our server. So basically I will be sending mails as a simple user to an other simple user. Like logging in to the outlook website and sending a simple e-mail.
The point of this small thing I want to do is to avoid the steps of sending an email(open browser, log in...etc).
And I am facing the connection problem to the port 25, which I have no idea why and what kind of problem it is.

Edited by AutID
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...