SMTP Mailer 0.9 [ by Thibault Imbert ]

SMTPMailer logo

During my AS3 session at the Flash Festival 2006 in Paris, i presented an application sending attached files through emails, with the Socket class available in the Player 9 and AS3.

A lot of people were asking for the source code to do the job, here is the complete source code for Flash CS3, here is a little description of what's inside :)

Just drop me an email, if you use it in an application, that would be cool, i'd love seeing it in some projects !

Mailer.as : This class deals with the SMTP socket server, 2 methods are available for the moment (sendAttachedMail and sendHTMLMail) the first one sends an email with an attached file (picture or any kind of file), the second one sends only a simple HTML email.

Base64.as : To send attached files through the wire, you have to encode binary data to Base64 string which is the best solution for compatibilities with SMTP servers, the base64 string is decoded as binary by your mail manager.

JPEGEncoder.as : This class is included in the corelib package, it takes an incoming BitmapData and encode it as a JPEG stream.

PNGEnc.as : This class is included in the corelib package, this version had been optimised by Patrick Mineault from 5etdemi.com, it takes an incoming BitmapData and encode it as a PNG stream.

Update : In my example, a snapshot of the stage is done, of course you can pass any display objects (Video, MovieClip) to get captures from a webcam for instance. In the .fla demo, the Mailer class attaches picture files.

Update : 31/10/06 : Version 0.2 added MD5 encoding for boundary string

Update : 12/10/06 : Version 0.3 added the capability to send PNG, JPEG image files, appropriate image headers are auto-added, just pass now the image name without the extension, the Mailer class will read the header and add the extension for you and the appropriate headers, sources have been modified ;)

Update : 17/02/07 : Version 0.4 is dispatching proper events, added following events :

// event dispatched when mail is successfully sent
myMailer.addEventListener(SMTPEvent.MAIL_SENT, onMailSent);
// event dispatched when mail could not be sent
myMailer.addEventListener(SMTPEvent.MAIL_ERROR, onMailError);
// event dispatched when SMTPMailer successfully connected to the SMTP server
myMailer.addEventListener(SMTPEvent.CONNECTED, onConnected);
// event dispatched when SMTP server disconnected the client for different reasons
myMailer.addEventListener(SMTPEvent.DISCONNECTED, onDisconnected);

Update : 24/06/07 : Version 0.5 handles every kind of files for attachment (Content-Type: application/octet-stream) has been added for all kind of binary files. A few bugs have been fixed (thanks Marc), next version will include authentification.

Update : 03/07/07 : Version 0.6 handles authentification (thanks Wein Pearson). To authenticate, just call the authenticate method.

Update : 04/08/08 : Version 0.7 fixes some little bugs.

Update : 04/16/09 : Version 0.8 fixes one nasty bug and QMail support.

Update : 02/02/10 : Version 0.9 was refactored.

// event dispatched when the client has authenticated successfully
myMailer.addEventListener(SMTPEvent.AUTHENTICATED, onAuthSuccess);
// event dispatched when the client could not authenticate
myMailer.addEventListener(SMTPEvent.BAD_SEQUENCE, onAuthFailed);
// pass a username and password
myMailer.authenticate ("bob", "bob");

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 License.

Sources available here

Comments (130)

  1. Hector A wrote::

    Hi, im trying your fla, and im got it to work with one of my domine smtp, but i didn’t with others, does smtp need to be set with any special configuration ?, is there any authentication process we need to make to send mail with some servers ? i mean, should i identify my self as an user of the server ?
    Thanks in advice if you drop my a line. :D

    Friday, November 10, 2006 at 8:46 pm #
  2. thibault.imbert wrote::

    hi Hector,

    did you failed on an ISP SMTP server or on your private SMTP server ?

    Monday, November 20, 2006 at 3:17 am #
  3. mecklen wrote::

    Hi, it´s great to see, how easy it is to implement protocolls like SMTP with writeUTFBytes. I´ve thought we have to do it with cryptic bytes. I´m playing around with the Mailer.as and everything works fine in the authoring environment. I could connect to my mail server if I allow the local file in myTrustFiles.cfg. More infos here: http://probertson.com/articles/2006/10/06/local-remote-resources-local-swf/ (interesting fact, that an exe file is trusted per se). But my big problem is to connect with the Socket to my server if the swf is placed on a web server. There are no error messages, it simply doesn´t connect. I have a crossdomain.xml file in the root of the webserver. What else restrictions could there be?

    Tuesday, November 21, 2006 at 7:56 pm #
  4. tannoy wrote::

    Bonjour Thibault,

    Peux-t’on utiliser ta classe avec un serveur SMTP qui nécessite au préalable une authentification ?

    merci

    Tuesday, February 6, 2007 at 12:18 pm #
  5. thibault.imbert wrote::

    salut tannoy,

    quel type d’authentification par exemple ?

    Saturday, February 17, 2007 at 3:30 pm #
  6. jasmina wrote::

    hello,

    i’ve tried to download sources from many sites, but i couldn’t. is there any way to get code for smtp mailer?

    Thursday, March 22, 2007 at 5:38 pm #
  7. jasmina wrote::

    ok, i’ve implemented, but still i have problem with authentication

    Thursday, March 22, 2007 at 8:13 pm #
  8. Thibault Imbert wrote::

    hello jasmina,

    what kind of problems do you have ? :)

    cheers

    Sunday, March 25, 2007 at 10:07 pm #
  9. Joe wrote::

    The source link is leading to a 404 :-(

    Thursday, April 19, 2007 at 7:20 am #
  10. Thibault Imbert wrote::

    Hi Joe,

    I double checked the link, and it seems to work with no problem, can you test with another browser ?

    http://bytearray.org/wp-content/uploads/2006/10/smtp_mailer/smtp_mailer_version_0.4.zip

    cheers :)

    Thursday, April 19, 2007 at 10:16 am #
  11. Ronald wrote::

    Hi Thibault

    I downloaded and tried your code. It can send the email using the ISP SMTP via sendHTMLMail() method. However, the content is blank when I open the email. 1. Is there anything wrong with the variable pMess in the SMTPMailer.as ?

    Thanks and Best Regards
    Ronald

    Wednesday, May 2, 2007 at 1:27 pm #
  12. Thibault Imbert wrote::

    hi Ronald,

    I am going to check that tonight, and tell you :)

    cheers

    Thursday, May 3, 2007 at 5:06 pm #
  13. Thibault Imbert wrote::

    hi Ronald,

    it’s working for me, I double checked, which email client are you using ?

    Thursday, May 3, 2007 at 10:43 pm #
  14. Ronald wrote::

    Hi Thibault

    now it is working too. I just add “\r\n” before the pMess according to the smtp rfc protocol.

    Anyway, i am not using any email client like outlook express, etc.

    Thanks very much.
    Best Regards
    Ronald

    Tuesday, May 8, 2007 at 8:06 am #
  15. Thibault Imbert wrote::

    glad it works ;)

    Tuesday, May 8, 2007 at 12:41 pm #
  16. Alexander wrote::

    Hi Thibault,
    I been trying to get this SMTP class of yours to work for a while, but I just keep getting this error:
    Error #2044: Unhandled IOErrorEvent:. text=Error #2031: Socket Error.

    Any idea what it might be?

    PS! Thanks for uploading all the great source code :-P

    Tuesday, May 15, 2007 at 4:35 pm #
  17. Thibault Imbert wrote::

    Hi Alexander,

    If you get this error, it means that the SMTPMailer class could not connect to the host you specified. Try double checking the SMTP server address you entered.
    If it does not solve the problem, let me know ;)

    cheers

    Tuesday, May 15, 2007 at 6:52 pm #
  18. TJ Downes wrote::

    The download link for the project is broken :(

    Monday, June 4, 2007 at 5:36 pm #
  19. Thibault Imbert wrote::

    Hi TJ,

    I checked the link and it’s seems to work, can you check this link ?

    http://bytearray.org/wp-content/uploads/2006/10/smtp_mailer/smtp_mailer_version_0.4.zip

    cheers ;)

    Monday, June 4, 2007 at 5:53 pm #
  20. TJ Downes wrote::

    It’s working now, thanks!

    Monday, June 4, 2007 at 11:18 pm #
  21. Marc wrote::

    @Alexander: depending on your specific flash security settings your mailer is only allowed to connect to your smtp if it’s running as an .exe

    Tuesday, June 12, 2007 at 10:06 am #
  22. Ronald Ruly wrote::

    Hi Thibault,

    Using actionscript 3.0, Is it possible to implement the POP mailer to read and save the email attachment to local disk ? If yes, do you have any resource on that?

    Best Regards
    Ronald

    Tuesday, June 12, 2007 at 11:59 am #
  23. Thibault Imbert wrote::

    Hi Ronald,

    yes it’s possible for sure, Emmanuel Bonnet did a POPMail parser, you can check it here :

    http://blog.emmanuelbonnet.com/2007/02/08/connexion-pop-par-socket-as3/

    This version does not include attachement saving feature, but this could be added by checking the MIME Content-Disposition tag.

    Then you could decode the base64 string from the mail to a ByteArray and then even have a preview through the player before saving it (if the player can handle the format)

    maybe I can have a look if you want

    cheers :)

    Tuesday, June 12, 2007 at 1:06 pm #
  24. Ronald Ruly wrote::

    Hi Thibault

    Actually, I have implemented the basic POP mailer, but I am stuck on the attachement processing. I will look into the base 64 String. Thanks for your hint =)

    Best Regards
    Ronald

    Wednesday, June 13, 2007 at 8:12 am #
  25. kabukies wrote::

    How can i connect with my smtp server if i need validate my login and password?

    Thanks

    Friday, June 15, 2007 at 3:04 am #
  26. Thibault Imbert wrote::

    hi kabukies,

    this is a feature I am going to include as soon as possible :)

    cheers ;)

    Friday, June 15, 2007 at 12:02 pm #
  27. Jon B wrote::

    This is fantastic – however I’d like to the use the google mail smtp servers – they use SPA (secure password authentication) – will it be possible in a future update to allow for this functionality?

    Sunday, June 17, 2007 at 1:50 am #
  28. Thibault Imbert wrote::

    Hi Jon,

    yes it’s planned for the next update :)

    tks !

    Sunday, June 17, 2007 at 2:57 am #
  29. Jon B wrote::

    You are the best! Seriously I’ve looked at every one of your projects and they are all awesome and give me ideas :)

    Sunday, June 17, 2007 at 11:50 am #
  30. kabukies wrote::

    This weekend i have writen the code for authenticate connection.

    How can i send you?

    Monday, June 18, 2007 at 3:21 am #
  31. Thibault Imbert wrote::

    Hi kabukies,

    it’s great, you can send it to me at :

    thibault.imbert [at] gmail.com

    I’ll have a look :)

    tks !

    Monday, June 18, 2007 at 9:31 am #
  32. mike hington wrote::

    please i need a workable version of a php mailer that is very good and can send up to 500 emails at a time to reach inbox of the recipient

    Monday, June 18, 2007 at 9:57 am #
  33. Ronald Ruly wrote::

    Hi Thibault

    I modify the source code a bit in order to handle the attachment other than image.

    I want to ask you about the sending of attachment part, especially the byteArray insertion.

    How do you insert the bytes from file to the byteArray (byteArray in the argument of sendAttachedMail) ?

    I try to insert the bytes like below, but the email sent to the recipient has an attachment icon, but no file attached and the message body is empty.

    //source code
    var attachmentFile:File=new File();
    attachmentFile.nativePath=”C:\\Desktop\\smtpMailer.as
    var stream:FileStream=new FileStream();
    var data2:ByteArray=new ByteArray();
    stream.open(attachmentFile,FileMode.READ);
    stream.readBytes(data2,0,stream.bytesAvailable);
    //assume that the SMTP Mailer has been instantiated.
    _smtp.sendAttachedMail(pFrom,pTo,subject,content,data2,filename);

    Thanks and Best Regards
    Ronald

    Thursday, June 21, 2007 at 4:28 am #
  34. Marc wrote::

    Hello Thibault,

    just a minor thing: but the JPG MIME type in your SMTPMailer class is wrong. Instead of “Content-Type: image/jpg” there should be “Content-Type: image/jpeg”. For some mailclients it works the way it is, but for Apple Mail, Flickr (send images per mail) the correct MIME type should be used or the image won’t be recognized. See: http://en.wikipedia.org/wiki/Internet_media_type

    And at the end fo the mail after the jpg-block of data it should be finished with another md5-boundary followed by “–” as seen here: http://tools.ietf.org/html/rfc2046#section-5.1.4

    Thanks and best regards,
    Marc

    Saturday, June 23, 2007 at 5:24 pm #
  35. Thibault Imbert wrote::

    Hello Marc,

    Thanks a lot, I will update it :)

    Hello Ronald,

    I will post a new version handling authentification and attachment of different files :)

    Saturday, June 23, 2007 at 6:39 pm #
  36. Thibault Imbert wrote::

    Marc,

    Version 0.5 has fixed those bugs :)

    Tks

    Friday, June 29, 2007 at 3:01 pm #
  37. Matthew wrote::

    Hey Thibault,

    Any estimated release of a version with Authentication? I have a mini project Flash Contact Form and would love to use this Class in my project (full credit given of course).

    Thanks,
    Matt

    Monday, July 2, 2007 at 10:04 pm #
  38. Thibault Imbert wrote::

    Hello Matthew,

    Version 0.6 is available for download and includes authentication ;)

    Great to hear you will use it !

    cheers

    Tuesday, July 3, 2007 at 1:01 pm #
  39. bart wrote::

    Hi Thibault,

    what about security?

    I guess it’s not possible to use a smtp server if the flash player is located on a webserver, unless the smtp server is in the same domain, or the smtp server also has a crossdomain.xml available somewhere in that domain.

    Am i right?

    Bart

    Tuesday, July 10, 2007 at 12:58 am #
  40. Thibault Imbert wrote::

    Hi Bart,

    you are totally right :)

    Tuesday, July 10, 2007 at 8:40 am #
  41. Andrew wrote::

    Hey Thibault,

    Everything looks awesome here great job!! Forgive my ignorance though, would it be possible (because of the security Sandbox) to create a flash app that Access Gmail Servers from a different domain (www.mydomain.com) or even from localhost? I looked at the link from response number 23 (http://blog.emmanuelbonnet.com) however I do not speak french :(

    Any Help would be greatly appreciated!

    Cheers
    -Andrew

    Saturday, September 22, 2007 at 7:38 pm #
  42. oliver_l1 wrote::

    Hi,
    i can’t send eMails i get this error message:

    500 Unrecognized command

    Monday, October 22, 2007 at 12:43 am #
  43. Thibault Imbert wrote::

    Hi oliver,

    can you tell me more about it ?
    Can you show me your code ?

    cheers,

    Thibault

    Monday, October 22, 2007 at 12:46 am #
  44. oliver_l1 wrote::

    i used the fla in SMTP Mailer 0.6
    just to try out and i did not changed the code.

    i’m more than happy if you can help.

    hope my english is good enough:-)

    Monday, October 22, 2007 at 1:01 am #
  45. Thibault Imbert wrote::

    Hi Oliver,

    Which SMTP server do you want to use ?

    regards,

    Thibault

    Tuesday, October 23, 2007 at 2:31 am #
  46. oliver_l1 wrote::

    Hi,
    i want to use the following smtp servers:

    smtp.web.de and mail.gmx.net

    Thanks

    Tuesday, October 23, 2007 at 5:18 pm #
  47. Garth Gerstein wrote::

    Hey Thibault,

    I don’t seem to be able to get your email to work. I tried to download the source code for the smtp mailer and the link appears to be dead. I have been working on this same problem for weeks trhing to build an email client for Flash CS3. This code would be a huge help. Do you have another email address I can try, or can you renew the link for the source code? Thank you.

    Wednesday, October 31, 2007 at 7:19 pm #
  48. Thibault Imbert wrote::

    Hi Garth,

    Sorry I fixed the link :

    http://www.bytearray.org/wp-content/projects/smtpmailer/SMTPMailer%200.6.zip

    Should be ok now :)

    let me know

    cheers,

    Thibault

    Wednesday, October 31, 2007 at 8:08 pm #
  49. marceloooo wrote::

    Hi Thibalt,
    I was tryin’ to use your code but the email always arrive with error…
    attached with a 0(zero) kb attachment… or without any text…

    then studin’ your code I noticed that it needs a ‘this.writeUTFBytes (“\r\n”)’
    before ‘this.writeUTFBytes (“Content-Type: text/html; charset=UTF-8; format=flowed\r\n”);’ and ‘this.writeUTFBytes (pMess+”\r\n”);’ lines.

    thanx for this greate code!
    a huge…

    Friday, November 9, 2007 at 12:45 am #
  50. Thibault Imbert wrote::

    Hi Marcelo,

    Thanks for the fix ;)
    Happy you like it !

    kind regards,

    Friday, November 9, 2007 at 12:56 am #
  51. Tom wrote::

    This works almost perfectly for me when I run it locally. However, some email addresses don’t receive the email (but aren’t picked up by a spam collector either).

    Also, whenever I deploy it to my server it stops working. Any suggestions?

    Monday, November 12, 2007 at 7:45 am #
  52. Ronny wrote::

    hey Thibault!
    Great job, and very cool you are sharing all this with us. Thank you very much so far.

    I’ve downloaded the sources, however if i run your fla, i’m getting the same error as Alexander. (I’m on a mac).

    And i was also wondering… Authenticating in flash: isn’t that a bit of a risk? (since everyone could just decompile your SWF and just get a peek at your login details…)
    Or am i just talking bullocks?

    Greetings

    Monday, November 19, 2007 at 10:08 pm #
  53. Thibault Imbert wrote::

    Hi Ronny,

    If you get such an event (IOErrorEvent), try connecting to your SMTP server through Telnet or any terminal to make sure everything is running fine.

    This event is fired when the SMTPLibrary is not able to connect to the SMTP server.

    Concerning the security issue, of course it’s not a good practice to store such informations into your ActionScript code, but you retrieve those infos dynamically from a database and use them.

    Kind regards,

    Thibault

    Friday, January 11, 2008 at 2:56 am #
  54. paul wrote::

    Very nice job. And thank you for sharing this.

    I am getting this:
    Error #2044: Unhandled SecurityErrorEvent:. text=Error #2048: Security sandbox violation:

    http://www..com/Movie1.swf cannot load data from mail..net:25

    Though I’ve searched, I don’t see yet how to resolve this.

    If I run on local machine (not localhost) all works fine every time. As soon as I run from localhost (WAMP on my laptop) or from remote web server, I get above error.

    Wednesday, January 16, 2008 at 10:03 am #
  55. Ben wrote::

    I’m not sure if anyone has mentioned it already, within seconds I added a trace because I was certain it was nearly OK!

    But I was stuck on auth…

    private static const AUTHENTICATED:Number = 0xFD;

    So I did…

    private static const AUTHENTICATED_:Number = 0xEB;

    Wednesday, January 23, 2008 at 2:21 am #
  56. Thibault Imbert wrote::

    Hi Ben,

    and it worked ? :)

    regards,

    Thibault

    Wednesday, January 23, 2008 at 11:14 am #
  57. jeanphilippe wrote::

    Salut Thibault,
    Saurais tu pourquoi j’ai un message error (violation sandbox) quand je teste ton exemple en ligne ?
    ps : j’utilise un smtp tout simple de Orange.fr
    merci
    JP

    Tuesday, February 5, 2008 at 8:49 am #
  58. heh wrote::

    Hi, what mean this error and How i remove it?

    Socket error, please check the sendHTMLMail() method parameters
    Arguments : ,,,Picture file attached ! :)

    Wednesday, February 13, 2008 at 6:30 pm #
  59. Neo wrote::

    Hi i’ve been working on a medical quiz program for med school revision. i’d love to use your mailer to report an y problems wit the questions but i’m having difficulty getting it to authenticate, could you post or mail me an idiots guide, perhaps with example@gmail.com in the code as must admit i get lost easily as all still new to me!

    Wednesday, February 27, 2008 at 2:42 am #
  60. Neil wrote::

    Hi Thibault,

    I have never used sent email from flash before, I uploaded your demo to my webserver, I don’t see anything in the status window, not even an error, any ideas?

    Thanks

    Saturday, March 15, 2008 at 11:54 am #
  61. Neil wrote::

    Hi Thibault,

    I am trying to connect to mail.myserver.info not smtp, does this matter? also my port is listed as 26 not 25. I added a call to the authenticate method with my login details, I get a security sandbox error, any help would be appreciated.

    Saturday, March 15, 2008 at 12:38 pm #
  62. Neil wrote::

    Ok I have done quite a bit of research into why I am getting a security error, it seems to be related to socket policy files in 9.0.115.0.

    Warning: Timeout on xmlsocket://mail.neilbrown.info:843 (at 3 seconds) while waiting for socket policy file.

    There is a comprehensive guide to the changes in policy files.

    http://www.adobe.com/devnet/flashplayer/articles/fplayer9_security.html

    It looks to me like you have to serve a socket policy file from port 843.

    Any ideas??

    Neil

    Tuesday, March 18, 2008 at 12:58 am #
  63. Thibault Imbert wrote::

    Hi Neil,

    Yes, the latest version of the player needs a policy file available on port 843.

    If you do not provide such a file, you will get a security error.

    I will make some more tests and let you know. I’m just wondering where they are going with those security restrictions.

    kind regards,

    Thibault

    Tuesday, March 18, 2008 at 12:04 pm #
  64. Neil wrote::

    I am on shared hosting, I don’t think it is possible to use SMTPMailer now, I can’t see how I can serve a socket policy file over 843. The admin guys aren’t much help there either :(

    Tuesday, March 25, 2008 at 10:08 pm #
  65. Len wrote::

    Hi All,
    Has anyone got this working in Flex / AIR? If so an example would be greatly appreciated…
    Thanks.
    Len

    Wednesday, March 26, 2008 at 10:02 pm #
  66. Francesco wrote::

    Hi Thibault

    i tried SMTPMail and in Test Mode and i received this messages:

    Error :

    250 OK Sender ok

    Code :

    250
    Authentication Error
    Error :

    500 command unrecognized

    Tuesday, April 1, 2008 at 12:24 pm #
  67. Tyler wrote::

    Hi Thibault,
    When I run SMTP Mailer in Localhost or through mywebsite I get: Error #2044: Unhandled SecurityErrorEvent:. text=Error #2048: Security sandbox violation: cannot load data from smtp.free.fr:25.
    at one_fla::MainTimeline/frame1()

    And when I run it in testmode I get:
    Error :

    554 : Client host rejected: Access denied

    Code :

    554

    Tuesday, April 1, 2008 at 10:39 pm #
  68. optimusPaul wrote::

    When I try this all I ever get is:
    554 SMTP synchronization error

    I can’t seem to find any way to deal with this.

    Friday, May 23, 2008 at 8:40 pm #
  69. Hi Thibault.

    First, thanks for sharing it with us. Great work!

    I’d tried to it to work and initially it didn’t work. So, reading the comments I read what @Ben told us and the authentication procedure worked. But after it i had experienced some other problems that I fixed and now I have it working fine.

    So, besides my blog is in portuguese (I’m brazilian) I made available my test’s sources, and I put comments on the places I changed something to have your original code working for me. I would appreciate if you can take a look on it.

    In advance, I would like to keep contact with you because I want to implement some functionality like SSL authentication, and any help from you would be great.

    One more time, thanks a lot!

    Thursday, July 24, 2008 at 10:20 pm #
  70. Aleks wrote::

    Hey Thibault!

    Some magical creations you have provided to the community. Thanks!
    I am just wondering if you or anyone else has succesfully got the socket policy file for port 843 working, or if there are any workarounds?

    It would be nice if I didn’t have to fiddle around with perl to get sockets working on my domain so i can run this awesoem script.. thx…

    Friday, July 25, 2008 at 10:44 am #
  71. Aleks wrote::

    P.S.
    when this is on my server and i click sendmail.. nothing happens.. but running it locally from flash cs3, i get the following in my output window… Error #2044: Unhandled IOErrorEvent:. text=Error #2031: Socket Error.
    at SMTPMailer_fla::MainTimeline/SMTPMailer_fla::frame1()
    Error : Socket error, please check the sendAttachedMail() method parameters

    I am assuming from what I have read this is the issue with a policy file that needs to be served…

    thx!

    Friday, July 25, 2008 at 10:54 am #
  72. Thibault Imbert wrote::

    Hi Vicente,

    It’s great to see what you have done with the SMTPMailer library. I am very happy to see that you fixed a few lines which may cause problems on some SMTP servers.

    I will update the library right now, I tested you AIR app and will put a link to it on that post :)

    I will contact you by email for the SSL authentification so that we can talk about it.

    Friday, July 25, 2008 at 10:58 am #
  73. Deepak Nayak wrote::

    Hi Thibault,

    Thanks a lot for sharing this library.
    I have question. How to attach multiple file in one mail. I see that function ‘sendAttachedMail’ takes one file as parameter.
    -Deepak

    Friday, August 1, 2008 at 12:45 pm #
  74. Thibault Imbert wrote::

    Hi Deepak,

    It’s not implemented yet, but I can do that if you need it.

    let me know,

    best,

    Thibault

    Friday, August 1, 2008 at 10:10 pm #
  75. Deepak Nayak wrote::

    Hi Thibault,

    I am building AIR app which needs to send mail with multiple attachments. It will be great if you add support for multiple attachments.

    I had problem when using the library with SendMail8.12.10 server. sendHTMLMail works perfectly fine but sendAttachedMail does not. when I tried to attach text file with some message text, message body was missing when mail was received.

    I tried reading some SMTP docs and one doc mentioned that there should extra CRLF before and after writing “message text”+\r\n to the socket.

    It is working after making this change.

    Monday, August 4, 2008 at 12:00 pm #
  76. Mike wrote::

    Ok, so it sends mail perfectly for me, and attaches the file just fine. My question is, how to I reference the attached image in the html content of the message?

    I tried:

    this.mailer.sendAttachedMail(“mail@mail.com”, “mail@mail.com”, “TESTING”, “Here is the image!”, b, “image.jpg”);

    and

    this.mailer.sendAttachedMail(“mail@mail.com”, “mail@mail.com”, “TESTING”, “Here is the image!”, b, “cid:image.jpg”);

    but neither work. How am I supposed to get the attached image to show up in the body of the email?

    Tuesday, August 12, 2008 at 9:00 pm #
  77. Mike wrote::

    Actually, I think part of the problem is that the image that is being attached isn’t valid. It’s attaching a file called “image.jpg” but that image won’t open in any of my photo editing software, or in Outlook.

    Tuesday, August 12, 2008 at 11:57 pm #
  78. sbs wrote::

    thank you very much

    Saturday, September 13, 2008 at 5:51 pm #
  79. Jason wrote::

    I am having trouble using your library to connect to gmail. Has anyone had any success?

    Wednesday, September 17, 2008 at 3:20 am #
  80. Denis wrote::

    how send attachament image with email I´m try is it:

    var attachmentFile:File = kiosque.dir.resolvePath(“eventos/”+playerStack.eventId+”-”+playerStack.eventName+”/fotos/”+playerStack.workpictureId+”.jpg”);
    var stream:FileStream = new FileStream();
    var data2:ByteArray = new ByteArray();
    stream.open(attachmentFile,FileMode.READ);
    stream.readBytes(data2,0,stream.bytesAvailable);
    stream.close();
    mailer.sendAttachedMail(vlFrom, vlTo[0], vlSubject, vlBody, data2, playerStack.workpictureId+”.”+attachmentFile.extension);

    Tuesday, September 30, 2008 at 8:40 pm #
  81. borfg wrote::

    Hi,
    Am using the .7 version. When I attached a byte array of plain TEXT (utf8), the first few dozen characters of the resulting attachment file are truncated. Why is this?

    Monday, October 13, 2008 at 6:26 pm #
  82. borfg wrote::

    When using the .7 library and running in debug mode, this error continually pops up despite a successfull email send. Both your MAIL_SENT and MAIL_ERROR events are being dispatched. Here is the error message that pops up:

    “Error #2044: Unhandled sendError:. text=”

    Monday, October 13, 2008 at 6:30 pm #
  83. borfg wrote::

    To be more specific, when sending the TEXT data as an attachment, the first 57 chars are missing

    Monday, October 13, 2008 at 7:00 pm #
  84. Thibault Imbert wrote::

    Hi borfg,

    Can you please isolate the error and send me an example an fla ou flex project ?

    let me know,

    best,

    Thibault

    Monday, October 13, 2008 at 7:21 pm #
  85. borfg wrote::

    What is an email I can reach you at?

    Monday, October 13, 2008 at 7:28 pm #
  86. borfg wrote::

    I am just calling the sendAttachedEmail() method. What is happening is the following.

    A) I call your method sendAttachedEmail()

    B) The SMTP_EVENT.MAIL_ERROR event is dispatched (which I handle) with the following code/message

    code: 250 msg:250 MYSERVER.com Hello myhostname.com [my.ip.address], pleased to meet you

    C) SMTPEvent.MAIL_SENT is dispatched (which I handle) with the code/message =
    code:250 msg:250 Mail queued for delivery.

    I don’t understand why both events are being dispatched. When running my app, this error pops up ““Error #2044: Unhandled sendError:. text=””

    Monday, October 13, 2008 at 7:50 pm #
  87. Alfredo wrote::

    Hi,
    first thanks that you open sourced smptmailer.
    A great Work!!

    I got following Problem:
    When I Publish a Html from
    Flash that embends the STMPMAILER.swf , It can t connect to the email server.
    On the other side if i export as standalone than it works.

    Do you have a idea ?

    Grettings from Berlin
    Alfredo

    Sunday, October 19, 2008 at 6:45 pm #
  88. Fahrudin Paljus wrote::

    Hi it’s great :) Can you upload any examples how to use this(SMTPMailer) in Flex? Pls answer. Thanks

    Tuesday, October 28, 2008 at 2:15 am #
  89. borf wrote::

    I am just calling the sendAttachedEmail() method. What is happening is the following.

    A) I call your method sendAttachedEmail()

    B) The SMTP_EVENT.MAIL_ERROR event is dispatched (which I handle) with the following code/message

    code: 250 msg:250 MYSERVER.com Hello myhostname.com [my.ip.address], pleased to meet you

    C) SMTPEvent.MAIL_SENT is dispatched (which I handle) with the code/message =
    code:250 msg:250 Mail queued for delivery.

    I don’t understand why both events are being dispatched. When running my app, this error pops up ““Error #2044: Unhandled sendError:. text=””

    Thursday, October 30, 2008 at 6:50 pm #
  90. Loyaveadadods wrote::

    Спасибо за пост! Добавил блог в RSS-ридер, теперь читать буду регулярно..

    Thursday, November 13, 2008 at 12:20 am #
  91. Saravanan wrote::

    Hi,

    Getting error in flash while running the fla..

    here the error desciption..

    Error #2044: Unhandled IOErrorEvent:. text=Error #2031: Socket Error.
    at SMTPMailer_fla::MainTimeline/frame1()

    -sara
    http://www.designscripting.com

    Wednesday, November 19, 2008 at 5:16 pm #
  92. Carlos Martins wrote::

    Hi! is it possible to use with the gmail smtp?

    Many thanks in advance

    Wednesday, November 26, 2008 at 7:29 pm #
  93. Neil wrote::

    Hello,

    This is fantastic work, now that I finally figured out the flash security restrictions, good job well done.

    Wednesday, December 3, 2008 at 4:44 pm #
  94. Gilad Manor wrote::

    hi,
    I just wanted to share something with you guys,
    my ISP requires an authentication prior to sending mail, thus invoking the authenticate before sending mail prompted an error that there was an extra HELO command.
    this resulted with errors on all the other commands (the 500 unknown command thing)
    the resolution for this was commenting out the line:
    writeUTFBytes (“HELO “+sHost+”\r\n”); at SMTPMailer.sendHTMLMail
    now its working just fine and i’m so happy :)

    gilad

    Thursday, January 15, 2009 at 12:43 am #
  95. Thibault Imbert wrote::

    Hi Gilad,

    Interesting, I am happy it works fine for you now ;)

    best,

    Thibault

    Thursday, January 15, 2009 at 2:27 am #
  96. alex wrote::

    I am tryinig to use this code in my multiclip video player. I get it working fine in version 9 of flash but as soon as i test in version 10 of flash it stops working. I have setup up a socket server with Wowzamedia sever that is working and sending out a xml file but would be intrested to know if anyone has this working on a windows IIS 6 platform with out a load of perl cgi code to make it work .
    Cheers

    Alex.

    Sunday, January 25, 2009 at 9:32 pm #
  97. sanjay wrote::

    hi,
    I have developed application with the help of smtp mailer,it works fine for sending emails and attachments below 20kb file size.but it is not working for attachments greater than 20kb

    Thursday, January 29, 2009 at 6:48 pm #
  98. sanjay wrote::

    I am using gmail smtp server at port 465 .

    Thursday, January 29, 2009 at 6:51 pm #
  99. Bharat wrote::

    hi,
    I have developed application with the help of smtp mailer,it works fine for sending emails and attachments below 20kb file size.but it is not working for attachments greater than 20kb.

    Friday, February 6, 2009 at 3:57 pm #
  100. carli wrote::

    i want to catch “Error #2044: Unhandled IOErrorEvent:. text=Error #2031: Socket Error.”
    with a listener so I can send a message to the person trying to send the email, could you help pointing me in the right direction
    cheers
    carli

    Sunday, February 8, 2009 at 1:05 pm #
  101. Shravan wrote::

    i m currently using version 6 for sending mails its not working , can u please send the link where i can download higher version

    Wednesday, February 11, 2009 at 5:05 pm #
  102. Milos wrote::

    I implemented TLS support for SMTP Mailer and I tested it with gmail, so it works fine but just for messages that are below 16KB :( I used TLS from as3crypto library and it’s seems that it has some problem with TLS fragmentation, so it works only for first fragment of massage (16kb). So if anyone run on this problem and have more information about it, it would be great to share here, so we can upgrade SMTP Mailer to next level with full TLS support! Such an library would be really useful for many AS developers. And thank you Thibault for this.

    Cheers!

    Thursday, February 19, 2009 at 7:07 pm #
  103. Thibault Imbert wrote::

    Hi Milos,

    Sounds very cool, I have some more time now, can you send me your update to thibault {at} bytearray.org so that I can take a look ?

    This way we can make a new release of SMTPMailer with TLS support and some other new features I was thinking about.

    best,

    Thibault

    Thursday, February 19, 2009 at 7:28 pm #
  104. Rich wrote::

    I am having trouble sending XML data. I am pasting it in the message box and after creating my ByteArray as XML it works fine… except it is cutting off the first 100 or so characters. Please Help!

    Thursday, February 19, 2009 at 10:41 pm #
  105. Claudio Neto wrote::

    Hey,

    I’m from Brazil. So, if my English is terrible, I’m sorry.

    I have 3 InputText and I must send this information to an e-mail. Could your job work for me with some changes?

    Thanks for the help,

    Claudio

    Tuesday, March 3, 2009 at 1:51 am #
  106. Carlos Valdez wrote::

    very well coded!
    only a few problems with MIME “\r\n” with QMAIL:

    fixes:
    (1)
    in Base64.as @ line ~86 put:
    output += ‘\r\n’;
    instead of:
    output += ‘\n’;

    (2)
    in SMTPMailer.as @ line ~111 after:
    writeUTFBytes (“Content-Type: multipart/mixed; boundary=————”+md5Boundary+”\r\n”);
    add:
    writeUTFBytes(“\r\n”);

    (3)
    in SMTPMailer.as @ line ~127 after:
    writeUTFBytes (“Content-Transfer-Encoding: base64\r\n”);
    add:
    writeUTFBytes(“\r\n”);

    (4)
    in SMTPMailer.as @ line ~133 put:
    writeUTFBytes (“————–”+md5Boundary+”–\r\n”);
    instead of:
    writeUTFBytes (“————–”+md5Boundary+”\r\n”);

    thanks.

    Thursday, March 5, 2009 at 2:13 am #
  107. Carlos Valdez wrote::

    Another “patch” for QMAIL:

    in SMTPMailer.as @ line ~272:
    change:
    else if ( smtpReturn == SMTPMailer.ACTION_OK && (response.toLowerCase().indexOf (“queued”) != -1 || response.toLowerCase().indexOf (“accepted”) != -1) ) dispatchEvent ( new SMTPEvent ( SMTPEvent.MAIL_SENT, smtpInfos ) );
    to:
    else if ( smtpReturn == SMTPMailer.ACTION_OK && (response.toLowerCase().indexOf (“queued”) != -1 || response.toLowerCase().indexOf (“accepted”) != -1 || response.toLowerCase().indexOf (“qp”) != -1)) dispatchEvent ( new SMTPEvent ( SMTPEvent.MAIL_SENT, smtpInfos ) );

    QMAIL sends something like this on mail delivery:

    “250 ok (##########) qp (#####)”

    “qp” seems to be the string to look for to avoid erroneous error reports hehe.

    Cheers!

    Thursday, March 5, 2009 at 6:24 am #
  108. Phil King wrote::

    I am using SMTPMailer V7 in a Flex 2 environment and am experiencing this strange behavior: I am connecting; my server requires authentication and I am getting authentication OK; I am calling “sendHTMLMail” (no errors) and I get that I am disconnecting afterwards; and through this I get no errors but it never sends mail. Any ideas?

    Thanks,

    Phil

    Thursday, March 5, 2009 at 10:32 pm #
  109. Phil King wrote::

    More detail; this is what the Server is saying:

    250 2.1.0 Ok
    250 2.1.5 Ok
    503 5.5.0 : Data command rejected: Improper use of SMTP command pipelining
    221 2.7.0 Error: I can break rules, too. Goodbye.

    Friday, March 6, 2009 at 1:43 am #
  110. Carlos Valdez wrote::

    @Phil King
    Try patching the files as I said in commnet #106, some smtp servers dont validate output sent by this class.
    ————-
    We can listen to “Error #2044: Unhandled IOErrorEvent:. text=Error #2031: Socket Error.” in SMTPMailer.as and do some trace, but I don’t know how to throw a catchable error to the implementing clases. to listen to the error try this:

    public function SMTPMailer ( pHost:String, pPort:int)

    {

    super ( pHost, pPort );

    sHost = pHost;

    addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
    addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

    }

    public function ioErrorHandler(event:*):void{
    trace(“Error : Socket error, please check the sendHTMLMail() method parameters”);
    trace(“Arguments : ” + arguments );
    }

    Anyone know how to try/catch that error when creating an SMTPMailer instance (connecting) ?

    Thanks

    Monday, March 9, 2009 at 10:56 am #
  111. Joachim wrote::

    I’m having some problems when sending a mail with attached jpeg image to a gmail address… Gmail can’t preview/open/let me download the attachement. What can be the problem?

    Friday, May 29, 2009 at 3:07 pm #
  112. phanliem wrote::

    I’ve use your smtpMailer in my project and it works so great. Thank you very much.

    Thursday, August 13, 2009 at 9:12 am #
  113. Thibault Imbert wrote::

    Hu phanliem,

    Great to hear your like it and it was useful for you :)

    best,

    Thibault

    Thursday, August 13, 2009 at 10:34 am #
  114. phanliem wrote::

    Hi Thibault Imbert,
    I have some questions about SmtpMailer.
    1/The authenticate method need once at the begining or we need re-authenticate before send each mail?
    2/When I send a picture by sendAttachedMail. But sometime I’ve got a blank picture and cannot download it(with gmail).
    Thanks

    Wednesday, August 19, 2009 at 5:15 pm #
  115. phanliem wrote::

    @my 2nd problem: After many search, i think its just a gmail bug. Here is the solution for getting the picture attach:
    http://www.google.com/support/forum/p/gmail/thread?tid=6169e807f4937a4a&hl=en

    Wednesday, August 19, 2009 at 8:04 pm #
  116. Chiranjeevi wrote::

    Hi..
    I have successfully implemented you application in one of my AIR application and able to send mail

    Thanks for a great suppor.

    I wanted to send a same mail to multiple recipients.
    How can we accomplish this task.

    Help would be greatly appreciated

    Tuesday, September 15, 2009 at 3:31 pm #
  117. Hitesh Patel wrote::

    Hi Thibault,

    Thanks for sharing this wonderful utility. I am facing trouble when sending a HTML email WITHOUT an attachment. I get the below error every time I try to send an email.

    503 5.5.0 : Data command rejected: Improper use of SMTP command pipelining

    221 2.7.0 Error: I can break rules, too. Goodbye.

    Any thoughts?

    Thanks,
    Hitesh Patel

    Saturday, October 3, 2009 at 10:13 am #
  118. Tidwell wrote::

    OK – so has there been any progress on a socket 843 work-around? Seems that question is never answered… I have no option but to publish Flash 10 or greater and cannot get my app working without the 843/465 connection (not sure what the port 465 connection is for). Take a look here: http://tidwellcreative.com/ftc – my client expects this by Monday morning and after so much work implementing SMTPMailer, it’s all lost…

    Sunday, November 29, 2009 at 4:22 am #
  119. Gianluca wrote::

    Hi Thibault,
    you saved me a lot of work!

    I have implemented a rought code to catch error “#2031: Socket Error” during init process.

    In SMTPMailer.as
    import flash.events.IOErrorEvent;
    import flash.errors.IOError;

    public function SMTPMailer(pHost:String,pPort:int {
    // add this listener
    addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
    super(pHost,pPort);
    sHost = pHost;
    addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
    }

    private function ioErrorHandler(e:IOErrorEvent) {
    trace(“ioErrorHandler: “+e);
    }

    I have successfully implemented your class into a new AIR application for one of my customers.

    Thanks,
    Gianluca

    P.s.
    Sorry for my english :-P

    Sunday, November 29, 2009 at 2:04 pm #
  120. Gianluca wrote::

    Wops… use this function to handle IOErrorEvent inside SMTPMailer.as
    private function ioErrorHandler(e:IOErrorEvent) {
    trace(“ioErrorHandler: “+e.text);
    var smtpInfos:Object = {code:e.errorID, message:e.text};
    dispatchEvent(new SMTPEvent(SMTPEvent.MAIL_ERROR, smtpInfos));
    }

    Sunday, November 29, 2009 at 2:14 pm #
  121. Rajdeep Rath wrote::

    Hi

    i am trying your SMTP mailer in a AIR project. It doesn’t seem to work properly. I am using 0.8 version.

    I create the instance then call authenticate method in “onConnected” handler. But i get Error Code: 250. I looked up on Google and it seems 250 means “ok” for a SMTP server. The funny thing is that the authenticate method triggers “onMailError” with code : 250 instead of invoking “onAuthSuccess” or “onAuthFailed”.

    can you please help.

    Saturday, January 9, 2010 at 11:35 pm #
  122. Wyatt Biker wrote::

    I am using Flex and would like to test this library. Is there an documentation?

    Thanks

    Wednesday, February 3, 2010 at 6:44 am #
  123. yossi wrote::

    Thibault nice lib I also recommend the AlivePDF lib great work thanks

    Monday, March 8, 2010 at 8:16 pm #
  124. Bryce Bigger wrote::

    Has anyone been able to get GMail to work properly with SMTP? I can get my ISP and others to work, but I’d like to be able to get Gmail in the mix. Perhaps a snippet? Please? Thanks!

    Thursday, March 11, 2010 at 5:22 pm #
  125. brett wrote::

    Has there been any movement on the SSL/TLS front? Perhaps Milos can share his code?

    Tuesday, March 30, 2010 at 8:49 pm #
  126. jadd wrote::

    Hello all. Can someone help me with this class(thanks Thibault for sharing)? Any working example? I’m having the usual problems with my ISP. Please.

    Friday, April 2, 2010 at 9:10 am #
  127. lex wrote::

    Solution can be found here http://code.google.com/p/as3crypto/issues/detail?id=14#c0

    Monday, April 19, 2010 at 9:34 pm #
  128. Erik wrote::

    How does TLSEngine fix the problem? Could anyone post a working example using Gmail? Would be really helpful. Thanks!

    Monday, April 26, 2010 at 1:52 am #
  129. solastyear wrote::

    I’m currently building an application in Flex that utilizes SMTP Mailer to automatically send out emails to the user when a particular condition is satisfied. The application checks this condition every 30 seconds. The condition is satisfied based on new records being returned from a database table.

    The problem is as follows:

    When the condition is first satisfied, the email is delivered to the user with no issues.

    The second time the condition is satisfied, the email is not delivered. In the smtp logs, the delivery attempt appears to get hung up on the following line:

    354 Start mail input; end with .

    No error codes are present in the smtp logs, but I do trace the following event from the SMTP Mailer class:

    [Event type="mailError" bubbles=false cancelable=false eventPhase=2]

    When the condition is satisfied a third time, the email that was not delivered when the condition was satisfied the previous time is now delivered, along with the email for this instance.

    This pattern then repeats itself, with the next email not being sent followed by two emails being sent simulatneously when the condition is met again.

    The smtp server being used is Windows 2003, on an internal network. The email is being sent to an outlook account hosted on an exchange server that is also on this internal network.

    Here is the actionscript code that creates the SMTPMailer object:

    public var testMail:SMTPMailer = null;

    public function alertNotify()
    {
    Security.loadPolicyFile(“crossdomain.xml”);
    this.testMail = new SMTPMailer(“myserver.ec.local”,25);
    this.testMail.addEventListener(SMTPEvent.MAIL_SENT, onEmailEvent);
    this.testMail.addEventListener(SMTPEvent.MAIL_ERROR, onEmailError);
    this.testMail.addEventListener(SMTPEvent.DISCONNECTED, onEmailConn);
    this.testMail.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onEmailError);
    }

    Here is the code that creates the email body and calls the method to send the email:

    public function alertUser(emailAC:ArrayCollection):void {

    trace (“In alertUser() before send, testMail.connected = ” + testMail.connected.toString()); var testStr:String = ” Key Location Event Type Comment Update Time “; for each (var event:rEntity in emailAC) { testStr = testStr + “” + event.key.toString() + “” + event.xml.address.toString() + ” ” + event.xml.@municipality.toString() + “” + event.xml.@type.toString() + “” + event.xml.@comment.toString() + “” + event.xml.attribute(“update-time”).toXMLString() + “”; } testStr = testStr + “”; testMail.flush(); testMail.sendHTMLMail(“r@ec.ca”,”w@ec.ca”,”Event Notification”,testStr);

    }

    Really not sure where the email that gets hung up is being stored until it is finally sent….

    Any suggestions as to how to begin to remedy this issue would be much appreciated.

    Thursday, June 10, 2010 at 8:48 pm #
  130. frontal wrote::

    I ran into a number of the same issues as other commenters. I worked through them though and I’ve written about it here:

    http://www.frontalcode.com/forums/viewtopic.php?f=3&t=268#p506

    I ended up writing my own version of SMTPMailer in the Frontal language (like HTML+CSS+JavaScript for Flash) so if you don’t want to use Frontal directly, you’ll have a little work to do. But if you’re looking for ways of making SMTPMailer a little more robust or clues as to what might be going wrong then I think you can get some ideas there.

    Thursday, July 8, 2010 at 1:35 am #

Trackbacks/Pingbacks (6)

  1. [...] Post con enlace a la descarga: * SMTP Mailer 0.1 [...]

     
  2. [...] SMTP Mailer pertime que você se comunique com um servidor SMTP e realize envio de e-mails com arquivos anexos, tudo isso graças a nova classe Socket que incorpora o novo AS3, atualmente está em fase de desenvolvimento porém já funciona. SMTP Mailer Fonte dessa matéria [...]

     
  3. Dando la chapa » Blog Archive » Tamarin, después de la resaca on Tuesday, November 28, 2006 at 10:33 pm

    [...] En cualquier caso, otro que parece que sale bastante reforzado es ActionScript 3. Hemos pasado de “tontería de diseñadores” a clientes de VNC, emuladores de Commodore C64, clases que implementan el protocolo SMTP, y vaya usted a saber lo que nos espera. [...]

     
  4. [...] Best Actionscript Animation Packages (AS3) April 26th, 2007 — drawk | Edit There are many ways to animate in Flash and the best way is always scripting, or I mean code in AS3.  Flash has grown up quite a bit and now has a very fun coding language in AS3, when programming games or animations scripting is the way to go. You can even do stuff like make a SMTP server in it, ok maybe more useful is a binary socket asset loader. [...]

     
  5. Novo Blog » SMTP Maler para AS3 on Sunday, December 9, 2007 at 7:44 pm

    [...] Socket que incorpora o novo AS3, atualmente está em fase de desenvolvimento porém já funciona. SMTP Mailer Fonte dessa [...]

     
  6. Flash - ActionScript Bibliotheken und APIs | der hess on Thursday, April 30, 2009 at 5:15 pm

    [...] SMTP Mailing :AS3- Klasse für Email-Funktionalität [...]