
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");
This work is licensed under a Creative Commons Attribution 3.0 License.
Sources available here
Comments (130)
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.
hi Hector,
did you failed on an ISP SMTP server or on your private SMTP server ?
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?
Bonjour Thibault,
Peux-t’on utiliser ta classe avec un serveur SMTP qui nécessite au préalable une authentification ?
merci
salut tannoy,
quel type d’authentification par exemple ?
hello,
i’ve tried to download sources from many sites, but i couldn’t. is there any way to get code for smtp mailer?
ok, i’ve implemented, but still i have problem with authentication
hello jasmina,
what kind of problems do you have ?
cheers
The source link is leading to a 404
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
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
hi Ronald,
I am going to check that tonight, and tell you
cheers
hi Ronald,
it’s working for me, I double checked, which email client are you using ?
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
glad it works
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
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
The download link for the project is broken
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
It’s working now, thanks!
@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
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
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
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
How can i connect with my smtp server if i need validate my login and password?
Thanks
hi kabukies,
this is a feature I am going to include as soon as possible
cheers
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?
Hi Jon,
yes it’s planned for the next update
tks !
You are the best! Seriously I’ve looked at every one of your projects and they are all awesome and give me ideas
This weekend i have writen the code for authenticate connection.
How can i send you?
Hi kabukies,
it’s great, you can send it to me at :
thibault.imbert [at] gmail.com
I’ll have a look
tks !
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
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
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
Hello Marc,
Thanks a lot, I will update it
Hello Ronald,
I will post a new version handling authentification and attachment of different files
Marc,
Version 0.5 has fixed those bugs
Tks
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
Hello Matthew,
Version 0.6 is available for download and includes authentication
Great to hear you will use it !
cheers
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
Hi Bart,
you are totally right
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
Hi,
i can’t send eMails i get this error message:
500 Unrecognized command
Hi oliver,
can you tell me more about it ?
Can you show me your code ?
cheers,
Thibault
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:-)
Hi Oliver,
Which SMTP server do you want to use ?
regards,
Thibault
Hi,
i want to use the following smtp servers:
smtp.web.de and mail.gmx.net
Thanks
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.
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
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…
Hi Marcelo,
Thanks for the fix
Happy you like it !
kind regards,
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?
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
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
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.
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;
Hi Ben,
and it worked ?
regards,
Thibault
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
Hi, what mean this error and How i remove it?
Socket error, please check the sendHTMLMail() method parameters
Arguments : ,,,Picture file attached !
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!
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
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.
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
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
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
Hi All,
Has anyone got this working in Flex / AIR? If so an example would be greatly appreciated…
Thanks.
Len
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
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
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.
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!
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…
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!
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.
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
Hi Deepak,
It’s not implemented yet, but I can do that if you need it.
let me know,
best,
Thibault
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.
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?
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.
thank you very much
I am having trouble using your library to connect to gmail. Has anyone had any success?
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);
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?
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=”
To be more specific, when sending the TEXT data as an attachment, the first 57 chars are missing
Hi borfg,
Can you please isolate the error and send me an example an fla ou flex project ?
let me know,
best,
Thibault
What is an email I can reach you at?
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=””
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
Hi it’s great
Can you upload any examples how to use this(SMTPMailer) in Flex? Pls answer. Thanks
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=””
Спасибо за пост! Добавил блог в RSS-ридер, теперь читать буду регулярно..
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
Hi! is it possible to use with the gmail smtp?
Many thanks in advance
Hello,
This is fantastic work, now that I finally figured out the flash security restrictions, good job well done.
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
Hi Gilad,
Interesting, I am happy it works fine for you now
best,
Thibault
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.
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
I am using gmail smtp server at port 465 .
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.
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
i m currently using version 6 for sending mails its not working , can u please send the link where i can download higher version
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!
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
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!
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
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.
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!
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
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.
@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
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?
I’ve use your smtpMailer in my project and it works so great. Thank you very much.
Hu phanliem,
Great to hear your like it and it was useful for you
best,
Thibault
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
@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
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
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
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…
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
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));
}
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.
I am using Flex and would like to test this library. Is there an documentation?
Thanks
Thibault nice lib I also recommend the AlivePDF lib great work thanks
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!
Has there been any movement on the SSL/TLS front? Perhaps Milos can share his code?
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.
Solution can be found here http://code.google.com/p/as3crypto/issues/detail?id=14#c0
How does TLSEngine fix the problem? Could anyone post a working example using Gmail? Would be really helpful. Thanks!
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.
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.
Trackbacks/Pingbacks (6)
[...] Post con enlace a la descarga: * SMTP Mailer 0.1 [...]
[...] 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 [...]
[...] 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. [...]
[...] 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. [...]
[...] Socket que incorpora o novo AS3, atualmente está em fase de desenvolvimento porém já funciona. SMTP Mailer Fonte dessa [...]
[...] SMTP Mailing :AS3- Klasse für Email-Funktionalität [...]