Sign in to follow this  
Followers 0
Clever1mba

code of sending Email through Telnet

15 posts in this topic

#1 ·  Posted (edited)

hello i hope u guyz like this email sending code

but i need to improve this code

i have problem in tcpRecv need to get all recv command and display

any one like to improve this code then it will be gr8

#include <GUIConstants.au3>

GUICreate("SMTP 25 1.1 by AsimZameer")

GUICtrlCreateLabel ("Smtp :",  20, 10, 50)

GUICtrlCreateLabel ("From :",  20, 40, 50)

GUICtrlCreateLabel ("To :",  20, 70, 50)

GUICtrlCreateLabel ("Name :",  20, 100, 50)

GUICtrlCreateLabel ("Subject :",  20, 130, 50)

GUICtrlCreateLabel ("Body :",  20, 160, 50)

GUICtrlCreateLabel ("Status :",  5, 215, 50)

$input1 = GUICtrlCreateInput("mx1.mail.yahoo.com",70,10,250,20)

$input2 = GUICtrlCreateInput("snip",70,40,250,20)

$input3 = GUICtrlCreateInput("snip",70,70,250,20)

$input4 = GUICtrlCreateInput("asimzameer",70,100,250,20)

$input5 = GUICtrlCreateInput("test message",70,130,250,20)

$input6 = GUICtrlCreateInput("Hello WOW ASIM SMTP really Works",70,160,250,20)

$myedit=GUICtrlCreateEdit ("Readme: After click on Send Button Wait Until status = 3 When Status = 3 it Means Email Successfully sent & Please Fill all Boxs Correctly If SMTP Address Not Works Automatically Exit and Close "& @CRLF, 1,230,400,70,$WS_DISABLED)

$btn = GUICtrlCreateButton ("Send", 160, 310, 60, 20)

GUISetState ()

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

If $msg = $btn Then

$g_IP = GUICtrlRead($input1)

$sData1  = "HELO " & GUICtrlRead($input4) & @CRLF

$sData2  = "MAIL FROM: <" & GUICtrlRead($input2) &">" & @CRLF

$sData3  = "RCPT TO: <" & GUICtrlRead($input3) &"> "& @CRLF

$sData4  = "DATA" & @CRLF

$sData5  = "From:" & GUICtrlRead($input4) & "< " & GUICtrlRead($input2) &" >" & @CRLF

$sData6  = "To:" & GUICtrlRead($input3) & @CRLF

$sData7  = "Subject:" & GUICtrlRead($input5) & @CRLF

$sData8  = "Sender: Microsoft Outlook Express 6.00.2800.1158" & @CRLF

$sData9  = "Mime-Version: 1.0" & @CRLF

$sData10 = "Content-Type: text/plain; charset=US-ASCII" & @CRLF

$sData11 = @CRLF

$sData12 = GUICtrlRead($input6) & @CRLF

$sData13 = "." & @CRLF

TCPStartUp()

$socket = TCPConnect(TCPNameToIP($g_IP), 25)

If $socket = -1 Then Exit

$ret1  = GUICtrlSetData ($myedit,TCPSend($socket, $sData1) )

sleep(100)

$ret2  = GUICtrlSetData ($myedit,TCPSend($socket, $sData2) )

sleep(100)

$ret3  = GUICtrlSetData ($myedit,TCPSend($socket, $sData3) )

sleep(100)

$ret4  = GUICtrlSetData ($myedit,TCPSend($socket, $sData4) )

sleep(100)

$ret5  = GUICtrlSetData ($myedit,TCPSend($socket, $sData5) )

sleep(100)

$ret6  = GUICtrlSetData ($myedit,TCPSend($socket, $sData6) )

sleep(100)

$ret7  = GUICtrlSetData ($myedit,TCPSend($socket, $sData7) )

sleep(100)

$ret8  = GUICtrlSetData ($myedit,TCPSend($socket, $sData8) )

sleep(100)

$ret9  = GUICtrlSetData ($myedit,TCPSend($socket, $sData9) )

sleep(100)

$ret10 = GUICtrlSetData ($myedit,TCPSend($socket, $sData10) )

sleep(100)

$ret11 = GUICtrlSetData ($myedit,TCPSend($socket, $sData11) )

sleep(100)

$ret12 = GUICtrlSetData ($myedit,TCPSend($socket, $sData12) )

sleep(100)

$ret13 = GUICtrlSetData ($myedit,TCPSend($socket, $sData13) )

sleep(100)

EndIf

Wend

enjoy !!!!!!!!!!!!!

-----------------------------------------------------------------------

Edited by Melba23

Share this post


Link to post
Share on other sites



You should probably post this code in

AutoIt Forums > AutoIt v3 > Scripts and Scraps

this is where people post programs.. and helpful stuff

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

move to Scripts and Scraps

Share this post


Link to post
Share on other sites

ERROR

---

Line 38

TCPStartUp()

^ ERROR

Error: Unknown function name.

---


[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Share this post


Link to post
Share on other sites

doesnt even work for me :S

Share this post


Link to post
Share on other sites

it works perfect and i use some of this code now for my syslog server :P


das beste Windows Support Forum: Windows 2000 Helpline und tschüss den WindowsfehlernProgrammieren: Autoit 3 - wer braucht noch VBS ?!Programmieren: Autoit 3 Forum?

Share this post


Link to post
Share on other sites

Thanks I got it too work, but my status keeps going to 0 and won't change how do i fix this?


[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Share this post


Link to post
Share on other sites

Asimzameer,

Cool. I was so excited by this I've started to turn it into a UDF. I'll post it here when it's working. I've got a problem with the server unexpectely terminating the connection, and I'll be stuffed if I can work out why. Might have to post in support.

Regards

Walkabout.

Share this post


Link to post
Share on other sites

Asimzameer,

Cool. I was so excited by this I've started to turn it into a UDF. I'll post it here when it's working. I've got a problem with the server unexpectely terminating the connection, and I'll be stuffed if I can work out why. Might have to post in support.

Regards

Walkabout.

Here it is (Thanks to MHz for his help)

;===============================================================================
;
; Function Name:    _INetSmtpMail()
; 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_Subject       - Subject of eMail
;                   $as_Body        - Single dimension array containing the body of eMail as strings
; 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 = 5  -   Data send or SMTP Protocol error
; Authors:      Original function to send email via TCP     - Asimzameer
;                   Conversion to UDF                       - Walkabout
;
;===============================================================================
Func _INetSmtpMail($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body)
    
    Local $i_ReturnErrorCode
    Local $i_LocalErrorCode
    Local $v_Socket
    Local $s_IPAddress
    Local $i_SendReturn
    Local $i_Count
    Local $s_Send[10]
    
    If $s_SmtpServer = "" Or $s_FromAddress = "" Or $s_ToAddress = "" Or $s_FromName = "" Or StringLen($s_FromName) > 256 Then
        SetError(1)
        Return 0
    EndIf
    $i_LocalErrorCode = TCPStartup()
    If $i_LocalErrorCode = 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
    Sleep(100)
    $s_Send[0] = "HELO " & $s_FromAddress & @CRLF
    $s_Send[1] = "MAIL FROM: <" & $s_FromAddress & ">" & @CRLF
    $s_Send[2] = "RCPT TO: <" & $s_ToAddress & ">" & @CRLF
    $s_Send[3] = "DATA" & @CRLF
    $s_Send[4] = "From:" & $s_FromName & "< " & $s_FromAddress & " >" & @CRLF
    $s_Send[5] = "To:" & $s_ToAddress & @CRLF
    $s_Send[6] = "Subject:" & $s_Subject & @CRLF
;$s_Send[7] = "Sender: AutoIt3" & @CRLF
    $s_Send[7] = "Mime-Version: 1.0" & @CRLF
    $s_Send[8] = "Content-Type: text/plain; charset=US-ASCII" & @CRLF
    $s_Send[9] = @CRLF
    
    For $i_Count = 0 To UBound($s_Send) - 1
        $i_SendReturn = TCPSend($v_Socket, $s_Send[$i_Count])
        If $i_SendReturn = 0 Then
            TCPCloseSocket($v_Socket)
            TCPShutdown()
            SetError(5)
            Return 0
        EndIf
        Sleep(100)
        $s_Receive = TCPRecv($v_Socket, 1000)
    Next
    Sleep(100)
    For $i_Count = 0 To UBound($as_Body) - 1
        $i_SendReturn = TCPSend($v_Socket, $as_Body[$i_Count] & @CRLF)
        Sleep(100)
        If $i_SendReturn = 0 Then
            TCPCloseSocket($v_Socket)
            TCPShutdown()
            SetError(5)
            Return 0
        EndIf
        $s_Receive = TCPRecv($v_Socket, 1000)
        Sleep(100)
    Next
    $i_SendReturn = TCPSend($v_Socket, @CRLF & "." & @CRLF)
    If $i_SendReturn = 0 Then
        TCPCloseSocket($v_Socket)
        TCPShutdown()
        SetError(5)
        Return 0
    EndIf
    Sleep(100)
    TCPCloseSocket($v_Socket)
    TCPShutdown()
    Return 1
EndFunc  ;==>_INetSmtpMail

And simple wrapper script is:

#include <INetSmtpMail.au3>
$s_SmtpServer = "mysmtpserver.com.au"
$s_FromName = "My Name"
$s_FromAddress = "From eMail Address"
$s_ToAddress = "To eMail Address"
$s_Subject = "My Test UDF"
Dim $s_Body[2]
$s_Body[0] = "Testing the new email udf"
$s_Body[1] = "Second Line"
$Response = _INetSmtpMail($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $s_Body)
$err = @error
msgbox(0,"email",$Response)
msgbox(0,"error",$err)

Share this post


Link to post
Share on other sites

how do you attach a file to the e-mail?


[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Share this post


Link to post
Share on other sites

you are a genius, i love your program!!!!!!!!!!!!!!!!!! keep up the good work :):whistle:

Share this post


Link to post
Share on other sites

this is not working for me.. i am in a network where we are using http proxy authentification for internet access...

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