0
我想通过smtp使用端口465连接到我的gmail帐户,以便从我的应用程序内发送电子邮件,但连接失败...我的代码如下所示:发送邮件从Gmail使用SMTPMailer flex AIR应用程序
<?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 = "[email protected]";
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 = "[email protected]";
var to:String = "[email protected]";
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>
但它没有连接发送邮件!我究竟做错了什么??
非常感谢!
PS:SMTPMailer
myabe因为你是你使用了正确的身份验证信息发送邮件到你的自我, – mgraph 2012-03-08 14:06:25
最有可能的crossdomain.xml文件不存在;因此Flash不能直接调用该服务器。但是,我没有看到你的'主机'在代码中的任何地方定义,所以不能真正检查。 – JeffryHouser 2012-03-08 14:09:58
@mgraph是的,我使用相同的登录gmail.com页面! – sstauross 2012-03-08 15:00:15