我一直在寻找这个问题的答案。我已经下载并成功安装了PhoneGap的EmailComposer插件。我可以点击我的“电子邮件”按钮,电子邮件字段弹出没问题。问题是,我正在尝试预先填充“收件人:”字段和“主题”字段。我搜索了各种帖子(主要是在StackOverflow上),我看过一些类似的帖子,但没有关于这个完全相同的问题或真正的解决方案:
我试过的帖子: PhoneGap Email Composer Plugin How to send email using mail composer plugin in iphone using phone gap jQuery mobile
我能找到的最近的一直在这里: https://groups.google.com/forum/#!searchin/phonegap/EmailComposer/phonegap/ItUj30UZnig/XTaBK7B8ahsJ
但我对那里的解决方案没有任何好运。
如上所述。我要做的就是预填充“收件人:”和“主题:”字段。随附的EmailComposer.js文档如下所示:
// window.plugins.emailComposer
function EmailComposer() {
this.resultCallback = null; // Function
}
EmailComposer.ComposeResultType = {
Cancelled:0,
Saved:1,
Sent:2,
Failed:3,
NotSent:4
}
// showEmailComposer : all args optional
EmailComposer.prototype.showEmailComposer = function(subject,body,toRecipients,ccRecipients,bccRecipients,bIsHTML) {
var args = {};
if(toRecipients)
args.toRecipients = toRecipients;
if(ccRecipients)
args.ccRecipients = ccRecipients;
if(bccRecipients)
args.bccRecipients = bccRecipients;
if(subject)
args.subject = subject;
if(body)
args.body = body;
if(bIsHTML)
args.bIsHTML = bIsHTML;
cordova.exec(null, null, "EmailComposer", "showEmailComposer", [args]);
}
// this will be forever known as the orch-func -jm
EmailComposer.prototype.showEmailComposerWithCB = function(cbFunction,subject,body,toRecipients,ccRecipients,bccRecipients,bIsHTML) {
alert("email showEmailComposerWithCB?");
this.resultCallback = cbFunction;
this.showEmailComposer.apply(this, [subject,body,toRecipients,ccRecipients,bccRecipients,bIsHTML]);
}
EmailComposer.prototype._didFinishWithResult = function(res) {
this.resultCallback(res);
}
cordova.addConstructor(
function() {
if(!window.plugins) {
window.plugins = {};
}
// shim to work in 1.5 and 1.6
if (!window.Cordova) {
window.Cordova = cordova;
};
//window.plugins.emailComposer.showEmailComposer(subject,body,toRecipients,ccRecipients,bccRecipients,bIsHTML)
window.plugins.emailComposer = new EmailComposer();
}
);
以:
开头的实际行EmailComposer.prototype.showEmailComposer
永远不会被解雇。在面向公众方面,我有这个(它是有效的HTML,但我删除了一些标签用于发布目的:
<a onclick="cordova.exec(null, null, 'EmailComposer', 'showEmailComposer', [args]);">Send Email</a>
然后我有:
app.initialize();
var args;
首次加载页面时会发生这种情况。
关于我在这里做错了什么想法?
答案 0 :(得分:0)
(OP在问题编辑中回答。移至社区维基回答。请参阅Question with no answers, but issue solved in the comments (or extended in chat))
OP写道:我明白了!解决方案相对容易,但对于我的生活,我在最初的几个小时内无法得到它。
在您的HTML代码中,无论您的按钮在哪里,请输入:
<a onclick="sendEmail(); return false;">Send Email Now</a>
sendEmail()
函数是业务所在的位置,因此在同一页面上创建一个脚本标记并添加以下内容:
<script>
function sendEmail(){
window.plugins.emailComposer.showEmailComposer("subject","body", "recipient@something.com", "cc@something.com", "bcc@something.com",false);
}
</script>
在初始化应用程序后的同一HTML中,只需添加args变量:
app.initialize(); //under this
var args = {};
保持
EmailComposer.js
文件相同,一切都应该正常。为了寻找这个答案,我遇到了大量的帖子,人们可以通过主题线,但无法通过身体或其他任何东西。我测试了它,这将正确地通过所有领域。我希望这有助于某人。