Jump to content
Sign in to follow this  
IHaveLeftTheForum

Please read it must

Recommended Posts

IHaveLeftTheForum

Hi,

how to send email with yahoo account through autoit?

Thanks

Azeem

Share this post


Link to post
Share on other sites
Xenobiologist

Try this with your data.

#include <INet.au3>

$s_SmtpServer = "mail.gmx.net"
$s_FromName = ""
$s_FromAddress = ""
$s_ToAddress = ""
$s_Subject = "My Test UDF"
$s_UName = ""
$s_PWD = ""
Dim $as_Body[2]
$as_Body[0] = "Testing the new email udf"
$as_Body[1] = "Second Line"
$Response = _INetSmtpMailAuth($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_UName, $s_PWD, $s_Subject, $as_Body)
;~ $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

;===============================================================================
;
; Function Name:    _INetSmtpMailAuth()
; Description:  Sends an email using SMTP over TCP IP.
; Parameter(s):     $s_SmtpServer   - SMTP server to be used for sending email
;   $s_FromName     - Name of sender
;   $s_FromAddress  - eMail address of sender
;   $s_ToAddress    - Address that email is to be sent to
;   $s_Username     - Username for Authentication (bernd670)
;   $s_Passwd   - Password for Authentication (bernd670)
;   $s_Subject      - Subject of eMail
;                   $as_Body        - Single dimension array containing the body of eMail as strings
;                   $s_helo         - Helo identifier (default @COMPUTERNAME) sometime needed by smtp server
;                   $s_first        - send before Helo identifier (default @CRLF) sometime needed by smtp server
;                   $b_trace        - trace on a splash window (default 0 = no trace)
; Requirement(s): None
; Return Value(s): On Success - Returns 1
;   On Failure - 0 and sets
;                                           @ERROR = 1      -   Invalid Parameters
;                                           @ERROR = 2      -   Unable to start TCP
;                                           @ERROR = 3      -   Unable to resolve IP
;                                           @ERROR = 4      -   Unable to create socket
;                                           @ERROR = 5x     -   Cannot open SMTP session
;                                           @ERROR = 50x    -   Cannot send body
;                                           @ERROR = 5000   -   Cannot close SMTP session
; Authors:  Original function to send email via TCP     - Asimzameer
;                   Conversion to UDF                       - Walkabout
;                   Correction  Helo, timeout, trace        - Jpm
;                   Correction send before Helo             - Jpm
;   Include Authentication  - bernd670
;
;===============================================================================
Func _INetSmtpMailAuth($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Username, $s_Passwd, $s_Subject = "", $as_Body = "", $s_helo = "", $s_first = "-1", $b_trace = 0)
    
    Local $v_Socket
    Local $s_IPAddress
    Local $i_Count
    Local $s_Send[9]
    Local $s_ReplyCode[9];Return code from SMTP server indicating success
    
    If $s_SmtpServer = "" Or $s_FromAddress = "" Or $s_ToAddress = "" Or $s_Username = "" Or $s_Passwd = "" Or $s_FromName = "" Or StringLen($s_FromName) > 256 Then
        SetError(1)
        Return 0
    EndIf
    If $s_helo = "" Then $s_helo = @ComputerName
    If TCPStartup() = 0 Then
        SetError(2)
        Return 0
    EndIf
    StringRegExp($s_SmtpServer, "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)")
    If @extended Then
        $s_IPAddress = $s_SmtpServer
    Else
        $s_IPAddress = TCPNameToIP($s_SmtpServer)
    EndIf
    If $s_IPAddress = "" Then
        TCPShutdown()
        SetError(3)
        Return 0
    EndIf
    $v_Socket = TCPConnect($s_IPAddress, 25)
    If $v_Socket = -1 Then
        TCPShutdown()
        SetError(4)
        Return (0)
    EndIf
    
    $s_Send[0] = "EHLO " & $s_helo & @CRLF
;~  If StringLeft($s_helo,5) <> "EHLO " Then $s_Send[0] = "EHLO " & $s_helo & @CRLF
    $s_ReplyCode[0] = "250"

    $s_Send[1] = "AUTH LOGIN" & @CRLF
    $s_ReplyCode[1] = "334"
    $s_Send[2] = _Base64Encoding($s_Username) & @CRLF
    $s_ReplyCode[2] = "334"
    $s_Send[3] = _Base64Encoding($s_Passwd) & @CRLF
    $s_ReplyCode[3] = "235"
    $s_Send[4] = "MAIL FROM: <" & $s_FromAddress & ">" & @CRLF
    $s_ReplyCode[4] = "250"
    $s_Send[5] = "RCPT TO: <" & $s_ToAddress & ">" & @CRLF
    $s_ReplyCode[5] = "250"
    $s_Send[6] = "DATA" & @CRLF
    $s_ReplyCode[6] = "354"
    
    $s_Send[7] = "From: " & $s_FromName & " <" & $s_FromAddress & ">" & @CRLF & _
            "To: " & "<" & $s_ToAddress & ">" & @CRLF & _
            "Subject: " & $s_Subject & @CRLF & _
            "Mime-Version: 1.0" & @CRLF & _
            "Content-Type: text/plain; charset=US-ASCII" & @CRLF & _
            @CRLF
    $s_ReplyCode[7] = ""
    
    $s_Send[8] = @CRLF & "." & @CRLF
    $s_ReplyCode[8] = "250"

    ; open stmp session
    If _SmtpSend ($v_Socket, $s_Send[0], $s_ReplyCode[0], $b_trace, "220", $s_first) Then
        SetError(50)
        Return 0
    EndIf

    ; send header
    For $i_Count = 0 To UBound($s_Send) - 2
        If _SmtpSend ($v_Socket, $s_Send[$i_Count], $s_ReplyCode[$i_Count], $b_trace) Then
            SetError(50 + $i_Count)
            Return 0
        EndIf
    Next
    
    ; send body records (a record can be multiline : take care of a subline beginning with a dot should be ..)
    For $i_Count = 0 To UBound($as_Body) - 1
        ; correct line beginning with a dot
        If StringLeft($as_Body[$i_Count], 1) = "." Then $as_Body[$i_Count] = "." & $as_Body[$i_Count]
        
        If _SmtpSend ($v_Socket, $as_Body[$i_Count] & @CRLF, "", $b_trace) Then
            SetError(500 + $i_Count)
            Return 0
        EndIf
    Next
    
    ; close the smtp session
    $i_Count = UBound($s_Send) - 1
    If _SmtpSend ($v_Socket, $s_Send[$i_Count], $s_ReplyCode[$i_Count], $b_trace) Then
        SetError(5000)
        Return 0
    EndIf
    
    TCPCloseSocket($v_Socket)
    TCPShutdown()
    Return 1
EndFunc ;==>_INetSmtpMailAuth


;===============================================================================
;
; Function Name:    _Base64Encoding()
; Description:  Kodiert eine Zeichenfolge mit dem Base64-Verfahren
;   (http://de.wikipedia.org/wiki/Base64)
; Parameter(s):     $String - Zeichenfolge die kodiert werden soll
; Requirement(s): None
; Return Value(s): Kodierte Zeichenfolge
; Authors:  bernd670
;
;===============================================================================
Func _Base64Encoding($String)

    $strUmsetzung = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
    $strRetValue = ""

    For $i = 1 To StringLen($String) Step 3
        $strTok = StringMid($String, $i, 3)
        Switch StringLen($strTok)
            Case 3
                $iTokVal = (Asc(StringMid($strTok, 1, 1)) * 256 + _
                        Asc(StringMid($strTok, 2, 1))) * 256 + _
                        Asc(StringMid($strTok, 3, 1))
                $strTokCryt = StringMid($strUmsetzung, (BitAND($iTokVal, 63)) + 1, 1)
                $iTokVal = BitShift($iTokVal, 6)
                $strTokCryt = StringMid($strUmsetzung, (BitAND($iTokVal, 63)) + 1, 1) & $strTokCryt
                $iTokVal = BitShift($iTokVal, 6)
                $strTokCryt = StringMid($strUmsetzung, (BitAND($iTokVal, 63)) + 1, 1) & $strTokCryt
                $iTokVal = BitShift($iTokVal, 6)
                $strTokCryt = StringMid($strUmsetzung, (BitAND($iTokVal, 63)) + 1, 1) & $strTokCryt
                $strRetValue &= $strTokCryt

            Case 2
                $iTokVal = (Asc(StringMid($strTok, 1, 1)) * 256 + _
                        Asc(StringMid($strTok, 2, 1))) * 256
                $iTokVal = BitShift($iTokVal, 6)
                $strTokCryt = StringMid($strUmsetzung, (BitAND($iTokVal, 63)) + 1, 1)
                $iTokVal = BitShift($iTokVal, 6)
                $strTokCryt = StringMid($strUmsetzung, (BitAND($iTokVal, 63)) + 1, 1) & $strTokCryt
                $iTokVal = BitShift($iTokVal, 6)
                $strTokCryt = StringMid($strUmsetzung, (BitAND($iTokVal, 63)) + 1, 1) & $strTokCryt
                $strRetValue &= $strTokCryt & "="

            Case 1
                $iTokVal = Asc(StringMid($strTok, 1, 1)) * 65536
                $iTokVal = BitShift($iTokVal, 12)
                $strTokCryt = StringMid($strUmsetzung, (BitAND($iTokVal, 63)) + 1, 1)
                $iTokVal = BitShift($iTokVal, 6)
                $strTokCryt = StringMid($strUmsetzung, (BitAND($iTokVal, 63)) + 1, 1) & $strTokCryt
                $strRetValue &= $strTokCryt & "=="

        EndSwitch
    Next

    Return $strRetValue
EndFunc ;==>_Base64Encoding

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
IHaveLeftTheForum

Thanks for reply Xenobiologist,

let me try this & will be back with result.

Thanks!

M.Azeem

Share this post


Link to post
Share on other sites
IHaveLeftTheForum

Error:

Line 118 

If _SmtpSend ($v_Socket, $s_Send[0], $s_ReplyCode[0], $b_trace, "220", $s_first) Then
If ^Error

Error: Unknown function name.

Please solve this error.

Thanks!

Azeem

Edited by Azeem

Share this post


Link to post
Share on other sites
Xenobiologist

Hi,

those functions are now for internal use (with an addtional _ at the beginning).

You'll find them in AutoIt3\Beta\Include\Inet.au3

; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name...........: __SmtpTrace
; Description ...: Used internally within this file, not for general use
; Syntax.........: __SmtpTrace($str[, $timeout = 0])
; Author ........: Asimzameer, Walkabout
; Modified.......: Jpm
; ===============================================================================================================================
Func __SmtpTrace($str, $timeout = 0)
    Local $W_TITLE = "SMTP trace"
    Local $s_SmtpTrace = ControlGetText($W_TITLE, "", "Static1")
    $str = StringLeft(StringReplace($str, @CRLF, ""), 70)
    $s_SmtpTrace &= @HOUR & ":" & @MIN & ":" & @SEC & " " & $str & @LF
    If WinExists($W_TITLE) Then
        ControlSetText($W_TITLE, "", "Static1", $s_SmtpTrace)
    Else
        SplashTextOn($W_TITLE, $s_SmtpTrace, 400, 500, 500, 100, 4 + 16, "", 8)
    EndIf
    If $timeout Then Sleep($timeout * 1000)
EndFunc ;==>__SmtpTrace

; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name...........: __SmtpSend
; Description ...: Used internally within this file, not for general use
; Syntax.........: __SmtpSend($v_Socket, $s_Send, $s_ReplyCode, $b_trace[, $s_IntReply=""[, $s_first=""]])
; Author ........: Asimzameer, Walkabout
; Modified.......: Jpm
; ===============================================================================================================================
Func __SmtpSend($v_Socket, $s_Send, $s_ReplyCode, $b_trace, $s_IntReply="", $s_first="")
    Local $s_Receive, $i, $timer
    If $b_trace Then __SmtpTrace($s_Send)

    If $s_IntReply <> "" Then

    ; Send special first char to awake smtp server
    If $s_first <> -1 Then
    If TCPSend($v_Socket, $s_first) = 0 Then
    TCPCloseSocket($v_Socket)
    TCPShutdown()
    Return 1; cannot send
    EndIf
    EndIf

    ; Check intermediate reply before HELO acceptation
    $s_Receive = ""
    $timer = TimerInit()
    While StringLeft($s_Receive,StringLen($s_IntReply)) <> $s_IntReply And TimerDiff($timer) < 45000
    $s_Receive = TCPRecv($v_Socket, 1000)
    If $b_trace And $s_Receive <> "" Then __SmtpTrace("intermediate->" & $s_Receive)
    WEnd
    EndIf

    ; Send string.
    If TCPSend($v_Socket, $s_Send) = 0 Then
    TCPCloseSocket($v_Socket)
    TCPShutdown()
    Return 1; cannot send
    EndIf

    $timer = TimerInit()

    $s_Receive = ""
    While $s_Receive = "" And TimerDiff($timer) < 45000
    $i += 1
    $s_Receive = TCPRecv($v_Socket, 1000)
    If $s_ReplyCode = "" Then ExitLoop
    WEnd

    If $s_ReplyCode <> "" Then
    ; Check replycode
    If $b_trace Then __SmtpTrace($i & " <- " & $s_Receive)

    If StringLeft($s_Receive, StringLen($s_ReplyCode)) <> $s_ReplyCode Then
    TCPCloseSocket($v_Socket)
    TCPShutdown()
    If $b_trace Then __SmtpTrace("<-> " & $s_ReplyCode, 5)
    Return 2; bad receive code
    EndIf
    EndIf

    Return 0
EndFunc ;==>__SmtpSend

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
IHaveLeftTheForum

How to use this?

Can anyone please help me by sharing working UDF and scrip and also tell how to use ...

Thanks,

Azeem

Share this post


Link to post
Share on other sites
Melba23

Azeem,

Please do not bump your posts within 24 hours. :mellow:

Remember this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare. You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online. Be patient and someone will answer eventually. As Mega already has - twice! :P

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
IHaveLeftTheForum

Ok! No problem

I wait for answer.

Thanks,

Azeem

Edited by Azeem

Share this post


Link to post
Share on other sites
Xenobiologist

Did you try the piece of code I posted? What problems occured?


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
IHaveLeftTheForum

Thanks for reply,

i tried your code but not working.

here is Error:

Line 118 

If _SmtpSend ($v_Socket, $s_Send[0], $s_ReplyCode[0], $b_trace, "220", $s_first) Then
If ^Error

Error: Unknown function name.

Can you fix this error please?

Share this post


Link to post
Share on other sites
JohnOne

those functions are now for internal use (with an addtional _ at the beginning).

You'll find them in AutoIt3\Beta\Include\Inet.au3

__SmtpSend($v_Socket, $s_Send, $s_ReplyCode, $b_trace, $s_IntReply="", $s_first="")


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
IHaveLeftTheForum

Sorry but here is one more error

If __SmtpSend($v_Socket, $s_Send, $s_ReplyCode, $b_trace, $s_IntReply="", $s_first="") Then

If __SmtpSend($v_Socket, $s_Send, $s_ReplyCode, $b_trace, ^ ERROR

Error: Variable used without being declared.

Share this post


Link to post
Share on other sites
IHaveLeftTheForum

Sorry but here is one more error

If __SmtpSend($v_Socket, $s_Send, $s_ReplyCode, $b_trace, $s_IntReply="", $s_first="") Then

If __SmtpSend($v_Socket, $s_Send, $s_ReplyCode, $b_trace, ^ ERROR

Error: Variable used without being declared.

Please reply with working script!

Share this post


Link to post
Share on other sites
SmOke_N

Please reply with working script!

Follow directions!

You were asked not to bump your posts within 24 hours. You've failed to do so.

Now I'm NOT asking. Do it again, I will lock your thread and remove your posting privileges period.

*********

Don't even reply to this post, or I'll consider that a bump!


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Baraoic

Jos made a working one Here and smtp server is smtp.mail.yahoo.com I just tested it and it worked.

Share this post


Link to post
Share on other sites
Xenobiologist

The code I posted works well. I just tried it with gmx.

#include <INet.au3>
$s_SmtpServer = "mail.gmx.net"
$s_FromName = "Chef"
$s_FromAddress = "xxx@gmx.de"
$s_ToAddress = "xxx@gmx.de"
$s_Subject = "My Test UDF"
$s_UName = "xxx@gmx.de"
$s_PWD = "xxx"
#cs
    $arIniRead = IniReadSection(@ScriptDir & '\mails.ini', "mail")
    $s_SmtpServer = $arIniRead[1][1]
    $s_FromName = $arIniRead[2][1]
    $s_FromAddress = $arIniRead[3][1]
    $s_ToAddress = $arIniRead[4][1]
    $s_Subject = $arIniRead[5][1]
    $s_UName = $arIniRead[6][1]
    $s_PWD = $arIniRead[7][1]
    MsgBox(0, "", $s_SmtpServer & ' ' & $s_FromName & ' ' & $s_FromAddress & ' ' & $s_ToAddress & ' ' & $s_Subject & ' ' & $s_UName & ' ' & $s_PWD)
#ce

Dim $as_Body[2]
$as_Body[0] = "Testing the new email udf"
$as_Body[1] = "Second Line"
$Response = _INetSmtpMailAuth($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_UName, $s_PWD, $s_Subject, $as_Body)
;~ $Response = _INetSmtpMail($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, "", "", 1)
$err = @error
If $Response = 1 Then
    MsgBox(0, "Success!", "Mail sent")
Else
    MsgBox(0, "Error!", "Mail failed with error code " & $err)
EndIf

;===============================================================================
;
; Function Name:    _INetSmtpMailAuth()
; Description:  Sends an email using SMTP over TCP IP.
; Parameter(s):     $s_SmtpServer   - SMTP server to be used for sending email
;   $s_FromName     - Name of sender
;   $s_FromAddress  - eMail address of sender
;   $s_ToAddress    - Address that email is to be sent to
;   $s_Username     - Username for Authentication (bernd670)
;   $s_Passwd   - Password for Authentication (bernd670)
;   $s_Subject      - Subject of eMail
;                   $as_Body        - Single dimension array containing the body of eMail as strings
;                   $s_helo         - Helo identifier (default @COMPUTERNAME) sometime needed by smtp server
;                   $s_first        - send before Helo identifier (default @CRLF) sometime needed by smtp server
;                   $b_trace        - trace on a splash window (default 0 = no trace)
; Requirement(s): None
; Return Value(s): On Success - Returns 1
;   On Failure - 0 and sets
;                                           @ERROR = 1      -   Invalid Parameters
;                                           @ERROR = 2      -   Unable to start TCP
;                                           @ERROR = 3      -   Unable to resolve IP
;                                           @ERROR = 4      -   Unable to create socket
;                                           @ERROR = 5x     -   Cannot open SMTP session
;                                           @ERROR = 50x    -   Cannot send body
;                                           @ERROR = 5000   -   Cannot close SMTP session
; Authors:  Original function to send email via TCP     - Asimzameer
;                   Conversion to UDF                       - Walkabout
;                   Correction  Helo, timeout, trace        - Jpm
;                   Correction send before Helo             - Jpm
;   Include Authentication  - bernd670
;
;===============================================================================
Func _INetSmtpMailAuth($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Username, $s_Passwd, $s_Subject = "", $as_Body = "", $s_helo = "", $s_first = "-1", $b_trace = 0)

    Local $v_Socket
    Local $s_IPAddress
    Local $i_Count
    Local $s_Send[9]
    Local $s_ReplyCode[9];Return code from SMTP server indicating success

    If $s_SmtpServer = "" Or $s_FromAddress = "" Or $s_ToAddress = "" Or $s_Username = "" Or $s_Passwd = "" Or $s_FromName = "" Or StringLen($s_FromName) > 256 Then
        SetError(1)
        Return 0
    EndIf
    If $s_helo = "" Then $s_helo = @ComputerName
    If TCPStartup() = 0 Then
        SetError(2)
        Return 0
    EndIf
    StringRegExp($s_SmtpServer, "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)")
    If @extended Then
        $s_IPAddress = $s_SmtpServer
    Else
        $s_IPAddress = TCPNameToIP($s_SmtpServer)
    EndIf
    If $s_IPAddress = "" Then
        TCPShutdown()
        SetError(3)
        Return 0
    EndIf
    $v_Socket = TCPConnect($s_IPAddress, 25)
    If $v_Socket = -1 Then
        TCPShutdown()
        SetError(4)
        Return (0)
    EndIf

    $s_Send[0] = "EHLO " & $s_helo & @CRLF
;~  If StringLeft($s_helo,5) <> "EHLO " Then $s_Send[0] = "EHLO " & $s_helo & @CRLF
    $s_ReplyCode[0] = "250"

    $s_Send[1] = "AUTH LOGIN" & @CRLF
    $s_ReplyCode[1] = "334"
    $s_Send[2] = _Base64Encoding($s_Username) & @CRLF
    $s_ReplyCode[2] = "334"
    $s_Send[3] = _Base64Encoding($s_Passwd) & @CRLF
    $s_ReplyCode[3] = "235"
    $s_Send[4] = "MAIL FROM: <" & $s_FromAddress & ">" & @CRLF
    $s_ReplyCode[4] = "250"
    $s_Send[5] = "RCPT TO: <" & $s_ToAddress & ">" & @CRLF
    $s_ReplyCode[5] = "250"
    $s_Send[6] = "DATA" & @CRLF
    $s_ReplyCode[6] = "354"

    $s_Send[7] = "From: " & $s_FromName & " <" & $s_FromAddress & ">" & @CRLF & _
            "To: " & "<" & $s_ToAddress & ">" & @CRLF & _
            "Subject: " & $s_Subject & @CRLF & _
            "Mime-Version: 1.0" & @CRLF & _
            "Content-Type: text/plain; charset=US-ASCII" & @CRLF & _
            @CRLF
    $s_ReplyCode[7] = ""

    $s_Send[8] = @CRLF & "." & @CRLF
    $s_ReplyCode[8] = "250"

    ; open stmp session
    If __SmtpSend($v_Socket, $s_Send[0], $s_ReplyCode[0], $b_trace, "220", $s_first) Then
        SetError(50)
        Return 0
    EndIf

    ; send header
    For $i_Count = 0 To UBound($s_Send) - 2
        If __SmtpSend($v_Socket, $s_Send[$i_Count], $s_ReplyCode[$i_Count], $b_trace) Then
            SetError(50 + $i_Count)
            Return 0
        EndIf
    Next

    ; send body records (a record can be multiline : take care of a subline beginning with a dot should be ..)
    For $i_Count = 0 To UBound($as_Body) - 1
        ; correct line beginning with a dot
        If StringLeft($as_Body[$i_Count], 1) = "." Then $as_Body[$i_Count] = "." & $as_Body[$i_Count]

        If __SmtpSend($v_Socket, $as_Body[$i_Count] & @CRLF, "", $b_trace) Then
            SetError(500 + $i_Count)
            Return 0
        EndIf
    Next

    ; close the smtp session
    $i_Count = UBound($s_Send) - 1
    If __SmtpSend($v_Socket, $s_Send[$i_Count], $s_ReplyCode[$i_Count], $b_trace) Then
        SetError(5000)
        Return 0
    EndIf

    TCPCloseSocket($v_Socket)
    TCPShutdown()
    Return 1
EndFunc ;==>_INetSmtpMailAuth


;===============================================================================
;
; Function Name:    _Base64Encoding()
; Description:  Kodiert eine Zeichenfolge mit dem Base64-Verfahren
;   (http://de.wikipedia.org/wiki/Base64)
; Parameter(s):     $String - Zeichenfolge die kodiert werden soll
; Requirement(s): None
; Return Value(s): Kodierte Zeichenfolge
; Authors:  bernd670
;
;===============================================================================
Func _Base64Encoding($String)

    $strUmsetzung = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
    $strRetValue = ""

    For $i = 1 To StringLen($String) Step 3
        $strTok = StringMid($String, $i, 3)
        Switch StringLen($strTok)
            Case 3
                $iTokVal = (Asc(StringMid($strTok, 1, 1)) * 256 + _
                        Asc(StringMid($strTok, 2, 1))) * 256 + _
                        Asc(StringMid($strTok, 3, 1))
                $strTokCryt = StringMid($strUmsetzung, (BitAND($iTokVal, 63)) + 1, 1)
                $iTokVal = BitShift($iTokVal, 6)
                $strTokCryt = StringMid($strUmsetzung, (BitAND($iTokVal, 63)) + 1, 1) & $strTokCryt
                $iTokVal = BitShift($iTokVal, 6)
                $strTokCryt = StringMid($strUmsetzung, (BitAND($iTokVal, 63)) + 1, 1) & $strTokCryt
                $iTokVal = BitShift($iTokVal, 6)
                $strTokCryt = StringMid($strUmsetzung, (BitAND($iTokVal, 63)) + 1, 1) & $strTokCryt
                $strRetValue &= $strTokCryt

            Case 2
                $iTokVal = (Asc(StringMid($strTok, 1, 1)) * 256 + _
                        Asc(StringMid($strTok, 2, 1))) * 256
                $iTokVal = BitShift($iTokVal, 6)
                $strTokCryt = StringMid($strUmsetzung, (BitAND($iTokVal, 63)) + 1, 1)
                $iTokVal = BitShift($iTokVal, 6)
                $strTokCryt = StringMid($strUmsetzung, (BitAND($iTokVal, 63)) + 1, 1) & $strTokCryt
                $iTokVal = BitShift($iTokVal, 6)
                $strTokCryt = StringMid($strUmsetzung, (BitAND($iTokVal, 63)) + 1, 1) & $strTokCryt
                $strRetValue &= $strTokCryt & "="

            Case 1
                $iTokVal = Asc(StringMid($strTok, 1, 1)) * 65536
                $iTokVal = BitShift($iTokVal, 12)
                $strTokCryt = StringMid($strUmsetzung, (BitAND($iTokVal, 63)) + 1, 1)
                $iTokVal = BitShift($iTokVal, 6)
                $strTokCryt = StringMid($strUmsetzung, (BitAND($iTokVal, 63)) + 1, 1) & $strTokCryt
                $strRetValue &= $strTokCryt & "=="

        EndSwitch
    Next

    Return $strRetValue
EndFunc ;==>_Base64Encoding

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
Kkweit

Hi,

I'm sorry but your script don't works ! When i run it I got an error message with the code 53

Is there anybody who knows what it means ?

I'm writing a script and i need to send an email through a smtp server with authentification

I tried your script with no change but my credential and it don't works ! Heard something about a function for internal usage if it's the problem is there a way to make it works for all usage ?

Edited by Kkweit

Share this post


Link to post
Share on other sites
guwguw

Hi,

I'm sorry but your script don't works ! When i run it I got an error message with the code 53

Is there anybody who knows what it means ?

Here is the info from the Help file:

Success: Returns 1

Failure: Returns 0 and set @error

@error: 1 - Invalid Parameters

2 - Unable to start TCP

3 - Unable to resolve IP

4 - Unable to create socket

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

Share this post


Link to post
Share on other sites
guwguw

Guwguw

I want to see your code, post here your code please.

What code?

I took that information from the AutoIt Help file. If you are looking for some working script, just click on the button "Open this script" at the bottom of the Help information and adjust the values to match your own settings(which is the hard part, depending on your SMTP setup).

Edited by guwguw

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.