Hi,
  I am new to AIR/Flex/AS and have written a (cutdown) version of a
simple smtp mail send program.
All works fine (in this cutdown version and the more complex version).

However, the email server returns a number of messages as the mail is
sent.

The ProgressEvent.SOCKET_DATA  (handleNewData function) does not seem
to capture all the email return messages
In particular I want to capture the

250 2.0.0 Ok: queued as XYZ

message to confirm the message was sent.

Anyone know why all the messages are not captured by the handleNewData
and how I can correct this?

Thanks in advance.

My code is written in Adobe Air 2.5

My trace output is as follows:
=====================
Connecting to the mail server, example.com:25
         Response is: 220 example.com ESMTP Postfix
         Response is: 250 example.com
         Response is: 250 2.1.0 Ok
250 2.1.5 Ok
354 End data with <CR><LF>.<CR><LF>
250 2.0.0 Ok: queued as 2C0264F5FF
221 2.0.0 Bye


My code follows:
========================================

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009";
                                           
xmlns:s="library://ns.adobe.com/flex/spark"
                                           
xmlns:mx="library://ns.adobe.com/flex/mx"
                                           creationComplete="Smtp()">
        <fx:Declarations>
                <!-- Place non-visual elements (e.g., services, value objects) 
here
-->
        </fx:Declarations>

<s:Button label="Send Email" x="200" y="200" click="mail()"> </
s:Button>

        <fx:Script>
                <![CDATA[

                                import flash.net.Socket;
                                import flash.profiler.showRedrawRegions;
                                import flash.utils.ByteArray;

                                import mx.core.mx_internal;
                                import mx.utils.ObjectUtil;

                                private var socket:Socket;
                                private var serverURL:String;
                                private var serverPort:int = 25;
                                private var serverResponse:ByteArray = new 
ByteArray();
                                public var sendData:Array = new Array();
                                public var dataStr:String;


                                public function Smtp():void
                                {
                                        this.serverURL = "example.com";
                                        this.serverPort = 25;
                                        socket = new Socket();
        
socket.addEventListener(ProgressEvent.SOCKET_DATA,handleNewData);
                                        this.connectToServer();
                                }

                                public function mail():void
                                {
                                        dataStr ="HELO example.com" + "\r\n";
                                        sendString(dataStr);

                                        dataStr = "MAIL 
FROM:<[email protected]>\r\n";
                                        sendString(dataStr);

                                        dataStr = "RCPT 
TO:<[email protected]>\r\n";
                                        sendString(dataStr);

                                        dataStr = "DATA\r\n";
                                        sendString(dataStr);

                                        dataStr = "To: <[email protected]>\r\n";
                                        sendString(dataStr);

                                        dataStr = "Date: Wed Jan 26 2011 
07:49:31 PM\r\n"
                                        sendString(dataStr);

                                        dataStr = "Subject: Test\r\n";
                                        sendString(dataStr);

                                        dataStr = "My Text\r\n";
                                        sendString(dataStr);

                                        dataStr = ".\r\n";
                                        sendString(dataStr);

                                        dataStr = "QUIT\r\n";
                                        sendString(dataStr);
                                }

                                private function connectToServer():void
                                {
                                        trace("Connecting to the mail server, " 
+ serverURL + ":" +
serverPort);
                                        socket.connect(serverURL, serverPort);
                                }


                                private function sendString(dataStr:String):void
                                {
                                        var bytes:ByteArray = new ByteArray();
                                        bytes.writeMultiByte(dataStr, "UTF-8");
                                        socket.writeBytes(bytes);
                                        socket.flush();
                                }

                                private function 
handleNewData(event:ProgressEvent):void
                                {
                                        var numBytes:int = 
socket.bytesAvailable;
                                        serverResponse = new ByteArray();
                                        while(--numBytes >= 0)
                                        {
                                                var byte:int = 
socket.readUnsignedByte();
                                                serverResponse.writeByte(byte);
                                        }

                                        var response:String = 
serverResponse.toString();
                                        trace("\t Response is: " + response);
                                }


                ]]>
        </fx:Script>
</s:WindowedApplication>

-- 
You received this message because you are subscribed to the Google Groups "Flex 
India Community" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/flex_india?hl=en.

Reply via email to