Sign in to follow this  
Followers 0
nobby

Sending mail using TCPsend

8 posts in this topic

I have a little script that checks for free disk space and sends the result via email using TCPsend

The problem is that when the email arrives to the intended recipient, the FROM and TO fields are empty. Using the same sintax via telnet, TO and FROM are full.

Could someone offer any advice?

#include <GUIConstants.au3>
#include<file.au3>
$Free = DriveSpaceFree ( "c:" )
$Free = Round($Free, 2)
 
   $g_IP = "mailserver"
   Dim $sData[6]
   $sData[0]  = "HELO domain"  & @CRLF
   $sData[1]  = "MAIL FROM: sender" & @CRLF
   $sData[2]  = "RCPT TO: someone@domain" & @CRLF
   $sData[3]  = "DATA" & @CRLF
   $sData[4]  = "Subject: " & $Free & " MB free on  C Drive" & @CRLF
   $sData[5] = "." & @CRLF

   TCPStartup()
   $socket = TCPConnect(TCPNameToIP($g_IP), 25)
  
   If $socket = -1 Then Exit

   Dim $ret[6]
   For $x = 0 To 5
    $ret[$x] = TCPSend($socket, $sData[$x])
    sleep(100)
   Next

Thanks


CheersNobby

Share this post


Link to post
Share on other sites



I think, that sending email with TCPSend() is not possible...

Because usually TCPSend() needs TCPRecv() too.

Im sorry if im wrong!

Share this post


Link to post
Share on other sites

Actually randallc it is quite possible if you go read my thread about Server communicator.

Share this post


Link to post
Share on other sites

Hello

I agree...It's possible to do that an you are à 95% of the result. With you code, I receive the email with the "FROM" but not the "TO". But it arrives, so I am sure that it's just a question of one character less or more. I will try to find where with the help of Rebol (Internet script) because the sources of the "Send" command are readable.

Regards,

Francis

Share this post


Link to post
Share on other sites

Not tested it, but try to replace sleep(100) with this:

While 1
    $Recv = TCPRecv($socket,1024)
    If $Recv <> "" Then ExitLoop
WEnd

Sorry for my English, I'm Dutch... =DMedia UDFINet Adv UDF

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hello,

This works and Show the Sender and the TOer. I have found an exemple in

this forum which detailed how to send an Email with AutoIt ( I have searched HELO ).

HTH,

Regards,

Francis

#include <GUIConstants.au3>
#include<file.au3>
$Free = DriveSpaceFree ( "c:" )
$Free = Round($Free, 2)

   $g_IP = "MySmtp"
   Dim $sData[8]
   $sData[0]  = "HELO MyDomain"  & @CRLF
   $sData[1]  = "MAIL FROM: <MyEmail> " & @CRLF
   $sData[2]  = "RCPT TO: <MyEmail>" & @CRLF 
   $sData[3]  = "DATA" & @CRLF
   $sData[4]  = "Subject: " & $Free & " Mb free on  C Drive" & @CRLF
   $sData[5] = "From :<MyEmail>" & @CRLF
   $sData[6] = "To :<MyEmail>" & @CRLF
   $sData[7] = "." & @CRLF

   TCPStartup()
   
   $socket = TCPConnect(TCPNameToIP($g_IP), 25)
  
   If $socket = -1 Then Exit

   Dim $ret[8]
   For $x = 0 To 7
    $ret[$x] = TCPSend($socket, $sData[$x])
    sleep(100)
Next
Edited by Francis Lennert (France)

Share this post


Link to post
Share on other sites

Thanks for your help et merci de votre aide...

I found that it is very sensitive to syntax, such as the placement of colon

#include <GUIConstants.au3>

#include<file.au3>

$Free = DriveSpaceFree ( "c:" )

$Free = Round($Free, 2)

$g_IP = "MySmtp"

Dim $sData[8]

$sData[0] = "HELO MyDomain" & @CRLF

$sData[1] = "MAIL FROM: <MyEmail> " & @CRLF

$sData[2] = "RCPT TO: <MyEmail>" & @CRLF

$sData[3] = "DATA" & @CRLF

$sData[4] = "Subject: " & $Free & " Mb free on C Drive" & @CRLF

$sData[5] = "From :<MyEmail>" & @CRLF

$sData[6] = "To :<MyEmail>" & @CRLF - does not work

$sData[5] = "From: <MyEmail>" & @CRLF

$sData[6] = "To: <MyEmail>" & @CRLF - works

$sData[7] = "." & @CRLF

TCPStartup()

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

If $socket = -1 Then Exit

Dim $ret[8]

For $x = 0 To 7

$ret[$x] = TCPSend($socket, $sData[$x])

sleep(100)

Next


CheersNobby

Share this post


Link to post
Share on other sites

Sending a quit at the end is more stable.

#include <GUIConstants.au3>
#include<file.au3>
$Free = DriveSpaceFree ( "c:" )
$Free = Round($Free, 2)

$MailServer = "Server"
$sender = "me@domain.com"
$rcpt = "you@domain.com"
$subject = "Free Space on C" 
$body = $Free & " Mb free on  C Drive"

   Dim $sData[11]
   $sData[0]  = "HELO"  & @CRLF
   $sData[1]  = "MAIL FROM: " & $sender & @CRLF
   $sData[2]  = "RCPT TO: " & $rcpt & @CRLF
   $sData[3]  = "DATA" & @CRLF
   $sData[4]  = "Subject: " & $subject & @CRLF
   $sData[5]  = "From: " & $sender & @CRLF
   $sData[6]  = "To: " & $rcpt & @CRLF
   $sData[7]  = "" & @CRLF
   $sData[8]  = $body & @CRLF
   $sData[9]  = "." & @CRLF
   $sData[10] = "QUIT" & @CRLF

   TCPStartup()
   $socket = TCPConnect(TCPNameToIP($MailServer), 25)
  
   If $socket = -1 Then Exit

Dim $ret[11]
For $x = 0 To 10
    $ret[$x] = TCPSend($socket, $sData[$x])
    sleep(100)
Next

Someone an idea how to AUTH LOGIN?

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