简体   繁体   English

您如何从AIR桌面应用程序中发送电子邮件?

[英]How do you send an email from within an AIR Desktop Application?

I am trying to allow to the user to send an email from within an AIR Desktop application. 我试图允许用户从AIR桌面应用程序内发送电子邮件。 At first I tried: 一开始我尝试过:

navigateToURL(newURLRequest("mailto:someone@example.comSubject=Hello&Body=SomeText");

But this opens up an empty tab in the default internet browser. 但这会在默认的Internet浏览器中打开一个空选项卡。

Then I tried to use a php file, I uploaded it on a server. 然后,我尝试使用php文件,并将其上传到服务器上。 PHP code is: PHP代码是:

<?php
$to = ($_POST['recipientEmail']);
$subject = ($_POST['SenderName']);
$message = ($_POST['senderMesssage']);
$headers = "From: " . $_POST['senderName'] . " <" . $_POST['senderEmail'] .     ">\n";
if(@mail($to, $subject, $message, $headers))
{
    echo "answer=ok";
} 
else 
{
    echo "answer=error";
}
?>

and uploaded it on the following address: http://xespoofer.comxa.com/mail.php 并将其上传到以下地址: http : //xespoofer.comxa.com/mail.php

The actionscript side is: 动作脚本方面是:

var myVars:URLVariables = new URLVariables();
myVars.senderName = settings.companyName;
myVars.senderEmail =String(settings.settingsXML.Setting.@senderEmail);;
myVars.senderMesssage = String(settings.settingsXML.Setting.@Message);
myVars.recipientEmail = String(settings.settingsXML.Setting.@email);

var myURL:URLRequest = new URLRequest("http://xespoofer.comxa.com/mail.php");
myURL.method = URLRequestMethod.POST;
myURL.data = myVars;

var myLoader:URLLoader = new URLLoader();
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
myLoader.load(myURL);

The actionscript code runs when a button is clicked. 当单击按钮时,动作脚本代码运行。 The problem is nothing happens. 问题是什么也没发生。 The email is not sent. 电子邮件未发送。 Any help is greatly appreciated. 任何帮助是极大的赞赏。

I suggest you to add some listeners to detect what is happening. 我建议您添加一些侦听器以检测正在发生的情况。 I just tried (using hard coded strings, you should replace to use your proper data): 我刚刚尝试过(使用硬编码字符串,应替换以使用适当的数据):

var myVars:URLVariables = new URLVariables();
myVars.senderName = "name";
myVars.senderEmail =String("email@email.com");;
myVars.senderMesssage = String("Message");
myVars.recipientEmail = String("email2@email.com");

var myURL:URLRequest = new URLRequest("http://xespoofer.comxa.com/mail.php");
myURL.method = URLRequestMethod.POST;
myURL.data = myVars;

var myLoader:URLLoader = new URLLoader();
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
myLoader.addEventListener(Event.COMPLETE, completeHandler);
myLoader.addEventListener(ProgressEvent.PROGRESS, progressHandler);
myLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
myLoader.load(myURL);

function completeHandler(event:Event):void
{
    trace("completeHandler: ", URLLoader(event.target).data.toString());
}

function progressHandler(event:ProgressEvent):void
{
    trace("progressHandler");
}

function ioErrorHandler(event:IOErrorEvent):void
{
    trace("ioErrorHandler");
}

And the completeHandler method outputs: " answer=ok ". 并且completeHandler方法输出:“ answer=ok ”。 Debug it using your real data and check if you are passing the right values to senderName , senderEmail , senderMessage and recipientEmail . 调试它使用您的真实资料,确认是否要传递到正确的价值观senderNamesenderEmailsenderMessagerecipientEmail

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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