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();

Related Posts

13 Responses to “airxmail: How to get mail attachemnt files”

  • Alex より:

    Hi. Can somebody help me? I want to get some data about attachment file such as size and type(extention) of file without message loading.

  • coltware より:

    Hi Alex

    If you want to use POP3 protocol, you can NOT. It is protocol limitation.
    If you want to use IMAP4 protocol, IMAP4 support this, but airxmail doen’t support yet.

    But you can make your own code for that.

    Please refer to IMAP4 BODY command and BODY STRUCTURE command.

    At first, you make your subclass of IMAP4Command.
    Then please call

    If you want to know how to make subclass of IMAP4Command
    Please refere to following code
    IMAP4 FETCH Command

  • Alex より:

    OK. Thank you for the informative and quick answer.

  • Philipp より:

    I try to save the attachmend in the email,
    when i save the complete MimeMessage as an “.eml” i can open it with e.g. Outlook.
    But i dont find the Bytes of the Attachment.
    The Length of bodyByteArray and attachmendChilden is 0
    but Why ?
    Is the Attachment in an Different Array ?

    Sorry for my bad english.

  • coltware より:

    Hi philipp

    > when i save the complete MimeMessage as an “.eml” i can open it with e.g. Outlook.

    How do you parse e-mail message ?
    What is “.eml” file ?

    So please check these points.

    Check1 )
    Can you read main text message in airxmail ?

    Check2 )
    Can you find attachment part in your “.eml” file ?
    (using text viewer as you like )

    Every think is OK and
    ff you can show me the “.eml” file and your program,
    Please send me e-mail.

  • Konstantin より:

    Is it possible to get the orientation of an jpg-email-attachment. When I send an image from iPhone it is displayed in gmail correctly, but in my flex-app it’s upside down (apparently because it was shot this way)…
    Thanx a lot for your help – your api is great! :)

  • Konstantin より:

    Hi coltware,
    is it possible to (re)open a specific email from the mailbox?
    Currently I am using
    from your pop3 example code. Whicht loads all new email (since my last call) at once.
    If there are a lot/large attachments the app stands still for some while to process.

    Is it possible to load for instance all new “email-IDs”, store them and ask for a specific email according to its “eMail-ID” later? How would this code look like. Which function call(s) would I have to make?
    Any advice apreciated VERY much!!! 😉
    Thank you!

  • Konstantin より:

    Forget my (stupid) post from earlier – it’s all in your code! THANK YOU, I love it! 😉

  • kostas より:

    Dear Coltware,

    first of all thank you for this wonderful code. I’m using it in an air application and the only problem i have so far is that i cannot read (and save) email attachements.
    I’m following exactly your example (get mail attachement files) but always parameter “filename” is “”.
    I want to be able to get all the kind of files as attachment e.g .pdf,.doc.xls and etc.
    What am i doing wrong? Please give some instructions, it’s important for me.

    Thank you in advance,


  • coltware より:

    Hi kostas

    Plase check the e-mail source has content-disposition header or not.
    ex) Content-Disposition: attachment; filename=”XXXXXX.pdf”

    Or if you can show me the e-mail (has problem),
    please send me the e-mail source file.

  • kostas より:

    Dear coltware,
    I have sent the source for 2 emails to coltware at gmail dot com.
    Please check and give me instructions.

    Thank you

  • kostas より:

    Dear coltware,
    I sent zip attached to coltware at gmail dot com the .emls.
    Please check and advice.


  • j.c Pimentel J より:

    Hi, thanks for airxmail is very usefull , i’m trying to embed an image on a email . . but i can’t , . . i tried embebing the base64 code of the image into the img tag on a html message. . the html display but not the image, . . looking how gmail do this stuff i found that the use of a cid tag is the way to go , but theres an inconvenient i dont want to show the image as an attachment file on the mail , looking on the gmail source i look the header Content-Disposition: attachment isn’t there, after spending several hour figured out how to remove this on airxmail, i couldn’t do it, so that’s why i’m here, . . can you please help me with this? thanks a lot.

Leave a Reply

Spam protection by WP Captcha-Free

Add to Google
« 8月   12月 »