Posts Tagged ‘airxmail’

This is sample code for deleting a message with airxmail imap client class.

var client:IMAP4Client = ...;

I need information whether airxmail work well on ipad or not.

Recently I got same question from some peoples. in Japan and us and etc…
They says.
airxmail work well on ipad simulator, but does NOT work well on real ipad.
But I don’t have ipad or iphone.
So I need information.

If somebody have any information,
Please write comment or send me e-mail.


Save e-mail to local file
private function handleMessage(event:IMessageEvent):void{

 var msg:MimeMessage = event.getMimeMessage();
 var file:File = File.desktopDirectory.resolvePath("mail_" + msg.messageId + ".eml");

 var fs:FileStream = new FileStream();,FileMode.WRITE);
Re-parse and make MimeMessage from local file

The following example is required v0.7 or more.

// var dir:File = File.someDirectoryYouWantToUse

var list:Array = dir.getDirectoryListing();
var length:int = list.length;
for(var i:int = 0; idownload airxmail

You have to care 2 type of content type if you want to get html part of e-mail message.

1 ) text/html
2 ) multipart/alternative

1 ) text/html

In this case, you can get html content very easily.
The mime message only has one body part.

private function handleMessage(event:IMessageEvent):void{
  var msg:MimeMessage = event.getMimeMessage();
  var htmlText:String = msg.bodyText;
2 ) multipart/alternative

This case is slightly harder than case 1.
But airxmail support to access to child part using findParts method.

var parts:Array = msg.findParts("text/html");
  if(parts.length > 0){
    var htmlText:String = MimeBodyPart(parts[0]).bodyText;

Typically, text/html part is the only one.
So I think you don’t need to check first text/html part.

see source code


Can’t get email from POP3 or IMAP4 server with Airxmail.
Can’t send email to SMTP server with Airxmail.
But Why ?

But It is difficult to make the answer.
Because Airxmail is a library to communicate servers.
So you should know which is the problem, server or client ?

But How ??

Airxmail library support flex logging(mx.logging) functions.
So you can get debug logs using this functions.
The log text show you the communication between server and client.

1.Log sample ( IMAP and POP3 )
2.How to use flex logging functions.
  2-1 ) Output using standard( trace() ) classes.
  2-2 ) Output to file instead of trace()

Log sample


com.coltware.airxmail.imap.IMAP4Client set auth :
com.coltware.airxmail_internal.IMAP4 CMD[AX1000 CAPABILITY]
com.coltware.airxmail_internal.IMAP4 CMD[AX1001 LOGIN username password]
com.coltware.airxmail_internal.IMAP4 CMD[AX1002 NAMESPACE]
com.coltware.airxmail_internal.IMAP4 CMD[AX1003 LSUB "" "*"]
com.coltware.airxmail_internal.IMAP4 CMD[AX1004 SELECT "INBOX"]
com.coltware.airxmail.imap.command.SelectCommand OK...
com.coltware.airxmail_internal.IMAP4 CMD[AX1005 UID SEARCH SENTSINCE 1-Nov-2010]
com.coltware.airxmail.imap.command.IMAP4Command line>* SEARCH  237 238 239 240 241
com.coltware.airxmail_internal.IMAP4 CMD[AX1006 UID FETCH 241 RFC822.HEADER]
com.coltware.airxmail.MimeBodyPart create part object : [xxxx][object MimeMessage]
com.coltware.airxmail_internal.IMAP4 CMD[AX1007 UID FETCH 240 RFC822.HEADER]
com.coltware.airxmail.MimeBodyPart create part object : [xxxx][object MimeMessage]
com.coltware.airxmail_internal.IMAP4 CMD[AX1008 UID FETCH 239 RFC822.HEADER]
com.coltware.airxmail_internal.IMAP4 CMD[AX1051 SELECT "&TtVOiw-"]
com.coltware.airxmail_internal.IMAP4 CMD[AX1052 SELECT "&ZcWITA-"]
com.coltware.airxmail_internal.IMAP4 CMD[AX1053 LOGOUT]

“com.coltware.airxmail_internal.IMAP4 CMD[AXxxxx” is a request.


com.coltware.airxmail.pop3.POP3Client handleNotServiceReady :
com.coltware.airxmail.pop3.POP3Client [NO] +OK POP Gateway starting. <>
com.coltware.airxmail.pop3.POP3Client exec[USER username]
com.coltware.airxmail.pop3.POP3Client USER>+OK Password required for
com.coltware.airxmail.pop3.POP3Client exec[PASS xxxxxxx]
com.coltware.airxmail.pop3.POP3Client PASS>+OK 8 message(s) (45468 octets).
com.coltware.airxmail.pop3.POP3Client exec[UIDL]
com.coltware.airxmail.pop3.POP3Client UIDL>+OK uidl command accepted.
com.coltware.airxmail.pop3.POP3Client UIDL>1 798898888666525F84ZX55365F999671U
com.coltware.airxmail.pop3.POP3Client UIDL>2 798898888278645F84ZX54365F99986YX
com.coltware.airxmail.pop3.POP3Client UIDL>3 798898868173705F84ZX5Z365F99930YZ
com.coltware.airxmail.pop3.POP3Client UIDL>4 798898858076435F84ZX52365F999679W
com.coltware.airxmail.pop3.POP3Client UIDL>5 798898857787865F84ZX54365F99978Z4
com.coltware.airxmail.pop3.POP3Client UIDL>6 798898828171545F84ZX54365F9996X0Z
com.coltware.airxmail.pop3.POP3Client UIDL>7 798898808643695F84ZX51365F9994ZUX
com.coltware.airxmail.pop3.POP3Client UIDL>8 798898798097665F84ZX5V365F9998X3V
com.coltware.airxmail.pop3.POP3Client UIDL>.
com.coltware.airxmail.pop3.POP3Client exec[TOP 8 0]
com.coltware.airxmail.pop3.POP3Client [RETR]+OK 3082 octets
com.coltware.airxmail.pop3.POP3Client exec[QUIT]
2.How to use flex logging functions

Flex logging function is not depends output facility.
So you can decide the log output facility.
1st step: explain how to use flex logging using the class in FLEX SDK ( not depends on any library to output log )
2nd step: explain how to write log file using my classes
Because standard classes in FLEX SDK in only support standard output(?) ( trace() output ) as far as I know.

2-1 )

import mx.logging.Log;
import mx.logging.LogEventLevel;
import mx.logging.LogLogger;
import mx.logging.targets.TraceTarget;

private function init():void{
	var logTarget:TraceTarget = new TraceTarget();
	logTarget.filters = ["*"];
	logTarget.includeCategory = true;
	logTarget.level = LogEventLevel.DEBUG;

Please invoke init method in your initialize step.
In my usual case, I write these code.

<mx:WindowedApplication xmlns:mx="" width="100%" height="100%" xmlns:local="*"

That’s all.
You don’t need to write stace() function in your code.

You can see these code in airxmail library.

private static const log:ILogger = Log.getLogger("com.coltware.airxmail.imap.IMAP4Client");
private static const _log:ILogger = Log.getLogger("com.coltware.airxmail_internal.IMAP4");
_log.debug("CMD[" + cmd + "]");

Airxmail output a log automatically using flex logging functions.
You can see more detail at
Flex logging function is many functions , like filter output and change output format etc …

Current Airxmail subversion repository version has these 2 category.

“com.coltware.airxmail_internal.*” is low level log like protocol debug.
“com.coltware.airxmail.*” is more user level log.
But there was not clearly border, so please check the source code if you want to know more detail.

2-2 )
use FileTarget class in airxlib library.
FileTarget class support to write log file on your desktop pc.

import com.coltware.airxlib.log.FileTarget;

private function init():void{

  var fileTarget:FileTarget = new FileTarget(); = File.desktopDirectory;  //  set directory path
  fileTarget.filename = "airxmail.log";              //  set filename
  fileTarget.append = false;                             
  fileTarget.filters = ["*"];
  fileTarget.includeCategory = true;
  fileTarget.level = LogEventLevel.DEBUG;

Complete STARTTLS sample code

import com.coltware.airxmail.INetAddress;
import com.coltware.airxmail.MailSender.SMTPSender;
import com.coltware.airxmail.MimeMessage;
import com.coltware.airxmail.RecipientType;
import com.hurlant.crypto.tls.TLSSocket;

var sender:SMTPSender;

public function main():void{

public function initSender():void{
	sender = new SMTPSender();
	//  STARTTLS Handler

public function startTlsHandler(event:SMTPEvent):void{
	var sock:Socket = event.socket as Socket;
	var tls:TLSSocket = new TLSSocket();

public function sendPlainText():void{
	var mimeMsg:MimeMessage = new MimeMessage();
	var from:INetAddress = new INetAddress();
	from.personal = "Sample User";
	from.address = "";
	var toAddr:INetAddress = new INetAddress("toemail@xxxxxxx.xxxx","to address");
	// set mail subject
	mimeMsg.setSubject("Hello Airxmail");
	mimeMsg.setTextBody("this is body\r\n2n line");

starttls event fired if SMTP EHLO command result has STARTTLS.
ex )
00:04:07.694 [DEBUG] com.coltware.airxmail.smtp.SMTPClient [EHLO] at your service, []
00:04:07.694 [DEBUG] com.coltware.airxmail.smtp.SMTPClient [EHLO]:250-SIZE 35651584
00:04:07.694 [DEBUG] com.coltware.airxmail.smtp.SMTPClient [EHLO]:250-8BITMIME

00:04:07.694 [DEBUG] com.coltware.airxmail.smtp.SMTPClient [EHLO]:250-STARTTLS

00:04:07.694 [DEBUG] com.coltware.airxmail.smtp.SMTPClient [EHLO]:250 ENHANCEDSTATUSCODES

The STARTTLS extension is complex for a moment.
A smtp client have to connect the server with plain socket.
After the client gives STARTTLS command , the client have to change to tls socket from plain socket.

The following code is a sample to use STARTTLS command

// comment out because of using plain socket
//sender.setParameter(SMTPSender.SOCKET_OBJECT,new TLSSocket());


// chage to TLSSocket
public function startTlsHandler(event:SMTPEvent):void{
var sock:Object = event.socket as Socket;
var tls:TLSSocket = new TLSSocket();

tls.startTLS(sock,””); // <– please set “” as you like } [/as3]

I made airxmail swc file on google codes.
The file is draft implemetation version for IMAP4.
So if you don’t want to use draft version, please wait…

It doen’t support IMAP4 all functions.
But it is available to get e-mail message from imap server, like gmail imap.

These code are sample to connect and get message from gmail account.

Create client instance
import com.coltware.airxmail.imap.IMAP4Client;

private var client:IMAP4Client;

public function init():void{

	client = new IMAP4Client; = "";
	client.port = 993;
	client.socketObject = new SecureSocket();
mail flow to connect and get e-mail
//  Set handler for Folder Result

//  Set handler for UID list result ( uid is a key to get e-mail from server )

//  Set message handler 

//  Set username and password, and invoked connect method

//  get subscribed folder list

// logout 
Implemantation of folder result handler
private function folderListResult(event:IMAP4Event):void{
  var folder:IMAP4Folder = event.result as IMAP4Folder;
  trace("NAME=>[" + + " --> " + folder.nameUTF8 + "]");



If the folder’s noselect property is true, you can NOT select mailbox,



If you want to get ALL messages from the folder,


If you know the folder name ( ex “INBOX” ) and want to get ALL messages form the folder,
you don’t need to get folder list, so you can change main flow source as following below..


// client.lsubBlocking();
Implemantation of message get handler

// result for search method
private function uidList(event:IMAP4ListEvent):void{
for(var i:int = 0; i

If you want to know how to get e-mail message.
Please refer to HERE.

private	function messageHandler(e:POP3MessageEvent):void{
	var msg:MimeMessage = e.getMimeMessage();
	//  attachmentChildren are only parts has attachments files.
	//  Don't need to check all children to extract files
	var attaches:Array = msg.attachmentChildren;
	if(attaches.length > 0){
		for each(var attach:MimeBodyPart in attaches){
			if(attach is MimeBinaryPart){
				var binPart:MimeBinaryPart = attach as MimeImagePart;
				var bytes:ByteArray = attach.bodyByteArray;
				//  v0.5 and less than r69 version has BUG !!
				//  binPart.getHeader("Content-Disposition"); is both available
				var contentDisposition:MimeHeader = binPart.contentDisposition;
					var filename:String = contentDisposition.getParameter("filename");
					filename = MimeUtils.decodeMimeHeader(filename);
					log.debug("Filename => " + filename );
					//  save Desktop directory, plese change following codes as you like
					var file:File =	File.desktopDirectory.resolvePath(filename);
					var fs:FileStream = new	FileStream();,FileMode.APPEND);
var contentType:ContentType = ContentType.MULTIPART_MIXED;
var mimeMsg:MimeMessage = new MimeMessage(contentType);

var from:INetAddress = new INetAddress();
from.personal = 
from.address = "";

var toAddr:INetAddress = new INetAddress("","hello airxmail");
// set mail subject
mimeMsg.setSubject("Hello World"); 
mimeMsg.setTextBody("this is multipart message");  

//  Plain Text Part
var textPart:MimeTextPart = new MimeTextPart();
textPart.transferEncoding = "8bit";
textPart.setText("This is text body part \n This is 2nd line.");

//  Attachment part 
var filePart:MimeImagePart = new MimeImagePart();
Add to Google
« 2月