简体   繁体   中英

Send mail from gmail using SMTPMailer in flex AIR app

I am trying to connect to my gmail account via smtp using port 465 in order to sent emails from inside my app but connection fails...my code is shown below:

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                   xmlns:s="library://ns.adobe.com/flex/spark" 
                   xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>


<fx:Script>
    <![CDATA[       
        import org.smtp.*;
        import org.smtp.events.SMTPEvent;
        import org.smtp.mailer.SMTPMailer;
        private function sendIt():void{ 

            var host:String = "smtp.gmail.com";
            var port:int = 465;     
            var login:String = "mygmail@gmail.com";
            var pass:String = "mypassword";

            var mailer:SMTPMailer = new SMTPMailer(host,port);

            mailer.addEventListener(SMTPEvent.MAIL_ERROR,function(e:SMTPEvent):void{
            trace("error:"+e.toString());});

            mailer.addEventListener(SMTPEvent.AUTHENTICATED,function(e:SMTPEvent):void{
            trace("authent:"+e.toString());});

            mailer.addEventListener(SMTPEvent.BAD_SEQUENCE,function(e:SMTPEvent):void{
            trace("bad:"+e.toString());});

            mailer.addEventListener(SMTPEvent.CONNECTED,function(e:SMTPEvent):void{
            trace("connected:"+e.toString());});

            mailer.addEventListener(SMTPEvent.DISCONNECTED,function(e:SMTPEvent):void{
                trace("disconnected:"+e.toString());});

            mailer.addEventListener(SMTPEvent.MAIL_SENT,function(e:SMTPEvent):void{
            trace("mailsent:"+e.toString());});

            mailer.connect(host, port);
            mailer.authenticate(login,pass);


            var subject:String = "Got new MAil";
            var message:String = "new email using SMTPMailer";
            var from:String = "mygmail@gmail.com";
            var to:String = "mygmail@gmail.com";
            mailer.sendHTMLMail(from,to,subject,message);
            trace(mailer.connected);
            trace("end");

        }

]]>
</fx:Script>
<s:Button x="281" y="146" label="Send it!"
          click="sendIt();"/>
</s:WindowedApplication>

but it does not connect to send the mail!! what am i doing wrong??

Thanks a lot beforehand!

PS: SMTPMailer

使用Airxmail解决: http//code.google.com/p/airxmail/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM