Jump to content

Recommended Posts

Posted (edited)

the script below works perfectly with Gmail. but i tried it with Yahoo but i get a 'could not connect to the server' error and a 'the sender mailbox is unavailable' error im sure about the smtp server and the sender email.

#include <INet.au3>
#include <File.au3>

$sSmtpServer = "smtp.mail.yahoo.com" ; address for the smtp-server to use - REQUIRED
$sFromName = "xxxx" ; name from who the email was sent
$sFromAddress = "xxxx" ; address from where the mail should come
$sToAddress = "xxxx" ; destination address of the email - REQUIRED
$sSubject = "xxxx" ; subject from the email - can be anything you want it to be
$sBody = "xxx" ; the messagebody from the mail - can be left blank but then you get a blank mail
$sAttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed
$sCcAddress = "" ; address for cc - leave blank if not needed
$sBccAddress = "" ; address for bcc - leave blank if not needed
$sImportance = "Normal" ; Send message priority: "High", "Normal", "Low"
$sUsername = "xxxxx" ; username for the account used from where the mail gets sent - REQUIRED
$sPassword = "xxx" ; password for the account used from where the mail gets sent - REQUIRED
$iIPPort = 587 ; GMAIL port used for sending the mail

Enum _
        $g__INetSmtpMailCom_ERROR_FileNotFound = 1, _
        $g__INetSmtpMailCom_ERROR_Send, _
        $g__INetSmtpMailCom_ERROR_ObjectCreation, _
        $g__INetSmtpMailCom_ERROR_COUNTER

Const $g__cdoSendUsingPickup = 1 ; Send message using the local SMTP service pickup directory.
Const $g__cdoSendUsingPort = 2 ; Send the message using the network (SMTP over the network). Must use this to use Delivery Notification
Const $g__cdoAnonymous = 0 ; Do not authenticate
Const $g__cdoBasic = 1 ; basic (clear-text) authentication
Const $g__cdoNTLM = 2 ; NTLM
$gs_thoussep = "."
$gs_decsep = ","
$sFileOpenDialog = ""

; Delivery Status Notifications
Const $g__cdoDSNDefault = 0 ; None
Const $g__cdoDSNNever = 1 ; None
Const $g__cdoDSNFailure = 2 ; Failure
Const $g__cdoDSNSuccess = 4 ; Success
Const $g__cdoDSNDelay = 8 ; Delay

$bIsHTMLBody = False
$iDSNOptions = $g__cdoDSNDefault

;============================================================================================================================

_Sendmail($sFromName, $sSubject, $sBody, 'xx@xx.xx')

;============================================================================================================================

Func _Sendmail($sFromName, $sSubject, $sBody, $sToAddress)

    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
;~      #cs
            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() _
            )
;~      #ce
        ConsoleWrite("### COM Error !  Number: " & _INetSmtpMailCom_ErrHexNumber() & "   ScriptLine: " & _INetSmtpMailCom_ErrScriptLine() & "   Description:" & _INetSmtpMailCom_ErrDescription() & @LF)
    Else
        Dim $iMsgBoxAnswer
        $iMsgBoxAnswer = MsgBox(262208, "SUCCESS", ":-)", 5)
    EndIf

EndFunc   ;==>_Sendmail



;~ #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 = True, $bIsHTMLBody = True, $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

 

i only changed the SMTP server and the port, is there anything else should be changed?

Edited by Raywando
Posted (edited)
4 hours ago, Jos said:

So what port did you use for Yahoo?  465 works for me.

Jos

i tried bot 465 and 587

 

4 hours ago, DrOtosclerosi said:

I tried to telnet both 465 and 587, both worked.

Could you please try to run in cmd

telnet smtp.mail.yahoo.com 587

and see if connects?

 

Connecting To smtp.mail.yahoo.com...Could not open connection to the host, on port 465: Connect failed

Connecting To smtp.mail.yahoo.com...Could not open connection to the host, on port 587 : Connect failed

 

what could be the problem?

Edited by Raywando
Posted (edited)
7 minutes ago, Raywando said:

i tried bot 465 and 587

 

Connecting To smtp.mail.yahoo.com...Could not open connection to the host, on port 465: Connect failed

Connecting To smtp.mail.yahoo.com...Could not open connection to the host, on port 587 : Connect failed

 

what could be the problem?

So the problem is not in your script, but in the communication between your PC and "smtp.mail.yahoo.com" .

Try, in "cmd":

tracert smtp.mail.yahoo.com

So we can see where the connection fails.

Mine is:

1    <1 ms    <1 ms    <1 ms  *.*.*.* [CENSORED]
  2     1 ms     1 ms     1 ms  *.*.*.* [CENSORED]
  3    30 ms    30 ms    29 ms  *.*.*.* [CENSORED]
  4    31 ms    31 ms    30 ms  *.*.*.* [CENSORED]
  5    30 ms    30 ms    30 ms  *.*.*.* [CENSORED]
  6    31 ms    31 ms    33 ms  oath.mix-it.net [217.29.67.28]
  7    48 ms    48 ms    47 ms  UNKNOWN-87-248-107-X.yahoo.com [87.248.107.9]
  8    60 ms    58 ms    58 ms  UNKNOWN-66-196-65-X.yahoo.com [66.196.65.218]
  9    75 ms    78 ms    79 ms  UNKNOWN-66-196-65-X.yahoo.com [66.196.65.217]
 10    80 ms    80 ms    77 ms  et-1-1-0.msr1.ir2.yahoo.com [66.196.65.19]
 11    81 ms    76 ms    73 ms  lo0.fab1-1-gdc.ir2.yahoo.com [77.238.190.2]
 12    72 ms    77 ms    78 ms  usw2-1-lbb.ir2.yahoo.com [77.238.190.105]
 13    87 ms    74 ms    74 ms  smtp.mail.vip.ir2.yahoo.com [188.125.73.26]

...It will be 40$ for diagnostic and 80$ for solving the problem :P

Edited by DrOtosclerosi
Posted (edited)
10 minutes ago, DrOtosclerosi said:

So the problem is not in your script, but in the communication between your PC and "smtp.mail.yahoo.com" .

Try, in "cmd":

tracert smtp.mail.yahoo.com

So we can see where the connection fails.

...It will be 40$ for diagnostic and 80$ for solving the problem :P

sounds fair :P

Tracing route to smtp.mail.global.gm0.yahoodns.net [188.125.73.26]
over a maximum of 30 hops:

  1    <1 ms    <1 ms    <1 ms  192.168.1.1
  2     2 ms     2 ms     2 ms  xx.xx.xx.xx
  

looks like the router is blocking the port. is that right?

Edited by Raywando
Posted
Just now, Raywando said:

thats fair :P


Tracing route to smtp.mail.global.gm0.yahoodns.net [188.125.73.26]
over a maximum of 30 hops:

  1    <1 ms    <1 ms    <1 ms  192.168.1.1
  2     2 ms     2 ms     2 ms  xx.xx.xx.xx
  

looks like the router is blocking the port. is that right?

The router (1.1) redirect to the 2nd mysterious one...

which, if the connection hang there, is blocked after there.

Looks like the 2nd IP is responding (2ms) but then there is no 3rd connection.

I would not think about a port blocked by ISP due to the successful connection to GMail, but the problem isn't definitely in your script (that's for sure).

Try to use other servers, not yahoo, and see if it works.

Posted (edited)
5 minutes ago, DrOtosclerosi said:

The router (1.1) redirect to the 2nd mysterious one...

which, if the connection hang there, is blocked after there.

Looks like the 2nd IP is responding (2ms) but then there is no 3rd connection.

I would not think about a port blocked by ISP due to the successful connection to GMail, but the problem isn't definitely in your script (that's for sure).

Try to use other servers, not yahoo, and see if it works.

no it goes all the way until smtp.yahoo

i just thought everything is going well expect the first trace.

1    <1 ms    <1 ms    <1 ms  192.168.1.1
  2     3 ms     2 ms     2 ms  xx.xx.xx.xx this is my routers IP
  3     2 ms     2 ms     2 ms  10.224.53.130
  4     2 ms     2 ms     2 ms  10.224.61.34
  5     2 ms     3 ms     2 ms  jed-fyh-igw-sr-01 [86.51.2.50]
  6     3 ms     5 ms     6 ms  jed-fyh-igw-br-01 [86.51.2.222]
  7     6 ms     5 ms     5 ms  fyha-mgn-msr-01 [86.51.65.172]
  8   144 ms   144 ms   145 ms  pos-0-0-2-0.mgn.ashb.msr1.mobily.com.sa [86.51.65.67]
  9   147 ms   148 ms   146 ms  exchange-cust1.dc2.equinix.net [206.126.236.16]
 10   152 ms   152 ms   154 ms  ae-4-0.pat1.nyc.yahoo.com [216.115.104.121]
 11   148 ms   148 ms   148 ms  ae-8-pat2.loz.yahoo.com [216.115.100.27]
 12   157 ms   159 ms   156 ms  ae6.pat2.iry.yahoo.com [66.196.68.153]
 13   157 ms   159 ms   157 ms  UNKNOWN-66-196-65-X.yahoo.com [66.196.65.25]
 14   157 ms   157 ms   157 ms  lo0.fab3-1-gdc.ir2.yahoo.com [77.238.190.4]
 15   157 ms   157 ms   157 ms  usw1-1-lbb.ir2.yahoo.com [77.238.190.104]
 16   157 ms   156 ms   157 ms  smtp.mail.vip.ir2.yahoo.com [188.125.73.26]
Edited by Raywando
Posted
1 minute ago, Raywando said:

no it goes all the way until smtp.yahoo

i just thought everything is going well expect the first trace.


  1    <1 ms    <1 ms    <1 ms  192.168.1.1
  2     3 ms     2 ms     2 ms  xx.xx.xx.xx this is my routers IP
  3     2 ms     2 ms     2 ms  10.224.53.130
  4     2 ms     2 ms     2 ms  10.224.61.34
  5     2 ms     3 ms     2 ms  jed-fyh-igw-sr-01 [86.51.2.50]
  6     3 ms     5 ms     6 ms  jed-fyh-igw-br-01 [86.51.2.222]
  7     6 ms     5 ms     5 ms  fyha-mgn-msr-01 [86.51.65.172]
  8   144 ms   144 ms   145 ms  pos-0-0-2-0.mgn.ashb.msr1.mobily.com.sa [86.51.65.67]
  9   147 ms   148 ms   146 ms  exchange-cust1.dc2.equinix.net [206.126.236.16]
 10   152 ms   152 ms   154 ms  ae-4-0.pat1.nyc.yahoo.com [216.115.104.121]
 11   148 ms   148 ms   148 ms  ae-8-pat2.loz.yahoo.com [216.115.100.27]
 12   157 ms   159 ms   156 ms  ae6.pat2.iry.yahoo.com [66.196.68.153]
 13   157 ms   159 ms   157 ms  UNKNOWN-66-196-65-X.yahoo.com [66.196.65.25]
 14   157 ms   157 ms   157 ms  lo0.fab3-1-gdc.ir2.yahoo.com [77.238.190.4]
 15   157 ms   157 ms   157 ms  usw1-1-lbb.ir2.yahoo.com [77.238.190.104]
 16   157 ms   156 ms   157 ms  smtp.mail.vip.ir2.yahoo.com [188.125.73.26]

So is not blocked anywhere.

It's just the 587 and 465 ports which are not reachable by your connection.

That's quite strange, but it's a problem which is probably caused by some of Yahoo's policies.

Have you tried other SMTP servers except GMail and Yahoo? If not, it's the time to do it :)

Posted
3 minutes ago, DrOtosclerosi said:

So is not blocked anywhere.

It's just the 587 and 465 ports which are not reachable by your connection.

That's quite strange, but it's a problem which is probably caused by some of Yahoo's policies.

Have you tried other SMTP servers except GMail and Yahoo? If not, it's the time to do it :)

thats GMX server

Tracing route to mail.gmx.com [212.227.17.174]
over a maximum of 30 hops:

  1    <1 ms    <1 ms    <1 ms  192.168.1.1
  2     2 ms     2 ms    12 ms  xx.xx.xx.xx
  3     2 ms     2 ms     2 ms  10.224.53.130
  4     6 ms     6 ms     4 ms  10.224.61.34
  5     2 ms     2 ms     2 ms  jed-fyh-igw-sr-01 [86.51.2.50]
  6     3 ms     5 ms     5 ms  jed-fyh-igw-br-01 [86.51.2.222]
  7     6 ms     5 ms     5 ms  fyha-mgn-msr-01 [86.51.65.172]
  8    76 ms    76 ms    77 ms  linx-mgn-msr-01 [86.51.65.79]
  9    77 ms    75 ms    76 ms  linx.bb-c.the.lon.gb.oneandone.net [195.66.224.98]
 10    77 ms    77 ms    80 ms  ae-4.bb-b.bap.rhr.de.oneandone.net [212.227.120.49]
 11    78 ms    78 ms    78 ms  ae-0-0.gw-diste2-a.bap.rhr.de.oneandone.net [212.227.121.176]
 12    77 ms    77 ms    77 ms  mail.gmx.com [212.227.17.174]

Trace complete.

it didnt also work using the script. what do u suggest? 

Posted

I would try to disable Windows Firewall or any firewall you are using, and try again

But without complete access to your network (which i DON'T want to have :P ) it's impossible to tell which the problem is.

This is a case for the IT Technician you trust most ;)

Posted (edited)
15 hours ago, DrOtosclerosi said:

I would try to disable Windows Firewall or any firewall you are using, and try again

But without complete access to your network (which i DON'T want to have :P ) it's impossible to tell which the problem is.

This is a case for the IT Technician you trust most ;)

I agree with this, firewall or router firewall or on the router port blocking or redirecting 

But carefull with this, baddies can get on your network if not done correctly

 

Edited by Dwalfware

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
  • Recently Browsing   0 members

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