user1296259
user1296259

Reputation: 521

How to programmatically send an email from a Flash AIR MOBILE app

I am trying to figure out how to send an email from a Flash Mobile (smartphones: blackberries, iphones, androids) app using mxml and Flash using Flash Builder 4.6. My boss told me to find out if it is possible. So far, I have been doing a lot of searching around on the internet for an answer.

I found this website: http://www.bytearray.org/?p=27, that has some classes for sending email in flash, but #1, I don't know if they work in Mobile apps, and #2, I can't find any instructions or tutorials on how to use the classes to send a simple email.

I downloaded the package from the site and imported into my project, where I am trying to send the code. But without sample code on how to simply send an email, I am not entirely sure what all do, and nor am I sure how to determine things like what port number to construct the SMTPMailer object (the SMTPMailer object is included in that package, and it takes a host string and a port number integer in it's constructor), right now I am trying 80 or 8080 for the port number, and I've tried localhost and one of our server computers, 198.162.1.109 for the host.

Anyway, I keep getting this error: Error #2044: Unhandled IOErrorEvent:. text=Error #2031: Socket Error.

Here is some of my sample code:

[Bindable]
        private var mailer : SMTPMailer;

        private function init() : void {
            tbPass.displayAsPassword = true;
        }

        protected function btnClick_email(toAddress : String, fromAddress : String, pass : String) : void {
            mailer = new SMTPMailer("198.168.1.109", 8080);


            mailer.addEventListener(SMTPEvent.MAIL_SENT, onMailSent);
            mailer.addEventListener(SMTPEvent.MAIL_ERROR, onMailError);
            mailer.addEventListener(SMTPEvent.CONNECTED, onConnected);
            mailer.addEventListener(SMTPEvent.DISCONNECTED, onDisconnected);
            mailer.connect("hotmail.com", 8080);
            mailer.authenticate(toAddress, pass);
            mailer.sendHTMLMail(fromAddress, toAddress, "Subect", "Message");

        }

        private function onMailSent() : void {
            lblEmailResult.text = "Sent Mail";
        }

        private function onMailError() : void {
            lblEmailResult.text = "Error";
        }

        private function onConnected() : void {
            lblEmailResult.text = "Connected";
        }

        private function onDisconnected() : void {
            lblEmailResult.text = "Disconnected";
        }

Upvotes: 1

Views: 2996

Answers (3)

Chris Roy
Chris Roy

Reputation: 1

I've accomplished this in a commercial app I worked on. We used a native extension found in distriqt's set of tools. Google them. The full suite of tools is cheap, though if you have any issues, do not expect a quick reply. Their message tool is what you are looking for, and it is easy to use.

Upvotes: 0

SQLiteNoob
SQLiteNoob

Reputation: 3022

Can't you just use navigateToURL() for this?

Ie:

var request:URLRequest("mailto:[email protected]");
navigateToURL(request);

That's all - 2 lines :)

Upvotes: 0

a.s.t.r.o
a.s.t.r.o

Reputation: 3338

I would suggest using a back-end service to send emails, it is same as connecting to a SMTP mail server but it is more flexible.

That being said, it should work, the error you are getting is related to your host IP, are you sure you have SMTP server running on "198.168.1.109:8080"? First check if you can send mails from it before trying to do it trough Flex, if that is OK, then you should double check socket policy files:

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

Hope that helps

Upvotes: 1

Related Questions