var contentType:ContentType = ContentType.MULTIPART_MIXED;
var mimeMsg:MimeMessage = new MimeMessage(contentType);

var from:INetAddress = new INetAddress();
from.personal = 
from.address = "from.email.address@coltware.com";


mimeMsg.setFrom(from);
mimeMsg.setReplyTo(from);
var toAddr:INetAddress = new INetAddress("to.email.address@coltware.com","hello airxmail");
mimeMsg.addRcpt(RecipientType.TO,toAddr);
// set mail subject
mimeMsg.setSubject("Hello World"); 
mimeMsg.setTextBody("this is multipart message");  

//
//  Plain Text Part
//
var textPart:MimeTextPart = new MimeTextPart();
textPart.contentType.setParameter("charset","UTF-8");
textPart.transferEncoding = "8bit";
textPart.setText("This is text body part \n This is 2nd line.");
mimeMsg.addChildPart(textPart);

//
//  Attachment part 
//
var filePart:MimeImagePart = new MimeImagePart();
filePart.contentType.setMainType("image");
filePart.contentType.setSubType("jpeg");
filePart.setAttachementFile(File.desktopDirectory.resolvePath("image.jpg"),"fireworks.jpg");
mimeMsg.addChildPart(filePart);

Related Posts

29 Responses to “airxmail: plain text mail with attachments”

  • Shamskhalil より:

    Nice Library keep the good work. I tried using the api in flex (browser based project) but keep getting these errors:

    1046 :type was not found or was not a compile-time constant:File
    1046 :type was not found or was not a compile-time constant:Vector

    but when i convert the project to AIR, it compiles and run successfully! does this means that the library cannot be used in flex? Am using Flash builder with flex sdk 3.5 please help ! Thank you.

  • coltware より:

    Thanks for using airxmail library.

    Airxmail libary depends on AIR. Because flex(browser based) can’t connect to Mail server using TCP/IP Socket.

    Sorry…

  • Hi Coltware:

    It is fantastic, but i am having problem in your POP3 API, I have traced my email about 1102 emails.

    I follow this http://flex.coltware.com/as3-flex-air/airxmail/
    but the result_message is stopped on 51st message, would you mind how i can get entire message? and how i can select folder of messages?

    Many thanks,
    Jack.

  • The Pop3 API keeps sending me email 2009 or lower year, i have reverse the UID and number from the list pop3EventList length any idea? your source code miss SocketJobSync, do you have idea for it?

  • coltware より:

    I’ll check my sources.
    Please wait a few days…..

    Sorry

  • sure thank you,
    i am glad getting answer from you, it is very magick and interesting plugin, but fortunately i can’t modify the script of source code, there’s missing com.coltware.commons.*

    These are the issues i faced in POP3:
    1. the pop3 grabs old email from google not the newest one.
    2. if you use client.uidl() it will get timeout so fast than client.list();
    3. no access to select folder like inbox
    4. no access to get attachment binary.

    Suggest:
    1. Your source has too much protected or private functions which some of they should be public because they are important for used out of its class.

    Overall, it is so fantastic. Thank you very much for sharing and did magick thing.

    Yacobus

  • coltware より:

    Hi yacobus

    I am so sorry. POP3Client have a bug…

    The bug was related to big ULID(or LIST) cmd result.
    So ‘handleData(pe:ProgressEvent)’ handler was invoked twice or more.
    But POP3Client ULID/LIST parsing was assuming it only once.

    Anyway I am fixing it…

  • coltware より:

    >Suggest:
    >1. Your source has too much protected or private functions which some of they should be >public because they are important for used out of its class.

    I don’t think I want to protect ‘com.coltware.commons.* package’
    But the package has buggy codes still now.
    Then I want split stable codes and developing code.
    But I don’t have time to do it….

  • Hi Bro,
    Do you have email? i am very interested to discuss and modify your script, but unfortunately i still can not compile your source because i miss the com.coltware.commons.*.

    Any way how Thanks for your fast reply. btw, i can get your fixes? and would you mind if the current google code is developing code and you share the repository with me, so that i can collaborate with you, because many people only care with *.swc only.

    Many Thanks,

  • > I don’t think I want to protect ‘com.coltware.commons.* package’

    That’s not about you protect the package, i was saying about protected function or methods that should be public function. Like in POP3 Event Classes, there setter function for result that i can not access it or no getter function, developer can do many magic things with this and also like override protected function handleData in POP3Client. :)

    Cheers.

  • coltware より:

    Hi yacobus

    Thank you. I am so grad to get your proposals.

    You can see my e-mail address at http://www.coltware.com/ ‘s footer.
    That’s japanese site, but please don’t care the contents.
    Or I’ll send you e-mail later.

    >That’s not about you protect the package, i was saying about protected function or

    Let’s talk about it !
    ( I’m sorry I have a time to write reply now … so soon later. )

  • Hi より:

    I am trying to read pdf attachements. I get pdf attachement as MimeBodyPart.I can save the data successfully but i dont know how come i can guess the file name.Can you help me regarding that?

  • coltware より:

    The following code specify the name “fireworks.jpg”.

    filePart.setAttachementFile(File.desktopDirectory.resolvePath(“image.jpg”),”fireworks.jpg”);

    But according the mail client enviroment, the file name doesn’t work well ( maybe ..).
    So please specify using content type header and content disposition header like following codes… as you like.

    var pdfPart:MimeBinaryPart = new MimeBinaryPart();
    pdfPart.setAttachementFile(File.desktopDirectory.resolvePath(“sample.pdf”));
    pdfPart.contentType.setParameter(“name”,”sample.pdf”);
    pdfPart.contentDisposition.setParameter(“filename”,”sample.pdf”);

  • Marjan より:

    Lovely library…
    I made this example including this library but I have this error:
    Unhandled ioError:. text=Error #2031: Socket Error. URL: smtp.gmail.com .Can anybody tell me why I can’t send email from my gmail account. Аlthough I put smtp.gamil.com in
    var sender:SMTPSender = new SMTPSender();
    sender.setParameter(SMTPSender.HOST,”smtp.gmail.com”);
    sender.setParameter(SMTPSender.PORT,465);
    I still can’t send mail.
    Thanks

  • coltware より:

    Hi marjan

    Mmmm, ioError is not related to airxmail.
    So it is difficult to find the correct reasons.
    But I tried many times to connect smtp.gmail.com.

    1) gmail server sometimes denied the connection.But I can’t find the reason.All I can do it try again.

    2) gmail server required to connect server with SSL/TLS sockets.
    IOError is not related to SSL/TLS, I think.
    But sooner or later, you have to use SSL/TLS sockets.
    So please try again with using SSL/TLS sockets.
    I recommended to use TLSSocket in as3crypto.
    Please refer to the following posts.

    http://flex.coltware.com/2010/07/24/how-to-use-tls-socket-in-airxmail/

    http://flex.coltware.com/2011/01/12/airxmail-how-to-use-starttls-extension-to-smtp2/

    3 ) Please try my e-mail client application(Gravity Mail).
    Gravity Mail is e-mail client application I am developing using airxmail library.
    http://flex.coltware.com/air-gravity-mail/
    Then please check to connect server and change the place.
    ( Office or your home, or etc…)
    Because if you are trying in your office, I don’t know you can use 465 port to go out for internet.

  • Marjan より:

    Thank you coldware. You’re genious…:))
    I had error because I did’t use TLSSocket. Now everything is working fine.:)
    You and your library are perfect…
    Thanks!

  • Marjan より:

    Coldware, I just want to tell you that from some networks(or internet connections) your(from the link) and my flex application cannot connect to smtp.gmail.com or other outgoing mail server. Do you know why?
    Thanks.

  • Marjan より:

    The error is: Error #2031.

  • coltware より:

    Hi marjan

    I can NOT get what you mean.
    The question is general network question or not ?

    At first, please try to check using telnet on your computer,
    Or in your network.

    ex)
    telnet smtp.gmail.com 465
    If you can NOT connect server, this is network problem.

    The network problem is very complicated,
    so if you can ask network manager for your network,
    Please ask them.

    If the network work fine, but AS script doen’t work well,
    Standard library (Socket or SecureSocket ) make this error code, so I recommend to make the sample code that just connect the server.

  • nona より:

    Thank you coltware.
    i am trying to send excel attachements,i dont know what i have to change.Can you help me ?

  • coltware より:

    Hi nona.

    Please see it.
    http://flex.coltware.com/2010/03/17/mail-attachements-airxmail-smtp/

    Note.
    1 ) Use MimeBinaryPart instead of MimeImagePart
    2 ) Option – set content-type as you like
    Default content-type is “binary/octet-stream”

    Regards

  • nona より:

    Thank you very much coltware for ypur help,
    i try it and it’s work perfectly 😉
    good luck

  • nona より:

    Hi again,
    i have some question about the attachment file, if i can send many pictures in one file compressed?

    thnx

  • coltware より:

    Hi nona.

    Please use my airxzip library to make zip file.
    http://flex.coltware.com/tag/airxzip/

    Regards

  • nona より:

    Thank you very much coldware. You’re helpful 😉

  • Boc Parker より:

    Hi,

    Would you like to help me ? I do exactly like in the tutorial. Emails sent well, but without attachment. I followed excatly this part for attachment.

    var filePart:MimeImagePart = new MimeImagePart();
    filePart.contentType.setMainType(“image”);
    filePart.contentType.setSubType(“jpeg”);
    filePart.setAttachementFile(File.desktopDirectory.resolvePath(“image.jpg”),”fireworks.jpg”);
    mimeMsg.addChildPart(filePart);

    Server is Gmail. The app is a Flex AIR app.

    Thank you so much.

    Emails sent successfully, but without attachment. Everything else works fine.

  • coltware より:

    Hi Boc

    Do you mean you prepared ‘image.jpg’ file on your desktop ?
    image.jpg file size is not huge ?
    (Gmail has limit for attachment file size )

    Which do you use TLS(SSL) library ? AS3Crypto or SecureSocket ( standard as3 class ).
    SecureSocket doesn’t work well on gmail.
    So if you don’t use AS3Crypto , please use it for gmail.

    Regards

  • Don より:

    Hi Coltware!

    I was able to solve my problem – attaching .csv files and preserving its filename and file type. I have a new question though – how to implement password checking when connecting to the smtp server (ex. gmail)?

  • coltware より:

    Hi Don

    Thank you for using my library. And so sorry my reply was late.

    >I have a new question though – how to implement password checking when connecting to the smtp server (ex. gmail)?

    please use SMTPEvent.SMTP_AUTH_NG event.

    SMTPClient.addEventListener(SMTPEvent.SMTP_AUTH_NG,smtpAuthError);

    private function smtpAuthError(evt:SMTPEvent):void{
    Alert.show(“smtp password was wrong”);
    }

Leave a Reply

Spam protection by WP Captcha-Free

RSS
Add to Google
2010年8月
« 7月   11月 »
1234567
891011121314
15161718192021
22232425262728
293031