【问题标题】:PhoneGap: Trying to pre populate email sent with Email ComposerPhoneGap:尝试预先填充使用电子邮件编辑器发送的电子邮件
【发布时间】:2015-01-27 18:10:13
【问题描述】:

我一直在寻找这个问题的答案。我已经下载并成功安装了 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;

页面首次加载时会发生这种情况。

关于我在这里做错了什么有什么想法吗?

【问题讨论】:

    标签: cordova


    【解决方案1】:

    (由 OP 在问题编辑中回答。已移至社区 wiki 答案。请参阅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 文件不变,一切都会好起来的。为了寻找这个答案,我遇到了大量的帖子,人们可以通过主题行,但不能通过身体或其他任何东西。我对其进行了测试,这将正确通过所有字段。我希望这对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-17
      • 2012-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-22
      • 1970-01-01
      相关资源
      最近更新 更多