meteorjs:我正在使用Email.send()吗? [英] meteorjs: Am I using Email.send() correctly?

查看:128
本文介绍了meteorjs:我正在使用Email.send()吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var SITE_URL = Meteor.absoluteUrl();

function sendEmailNotification(type, sourceUser, recipients, notificationObject) {
    var emailFrom = 'server@example.com';
    var emailSubject = 'MyApp: ';
    var emailBody = '';
    $.each(recipients, function (index, recipient) {
        recipients[index] = recipient + '@example.com';
    });

    switch(type) {
        case 'item_assigned':
            emailSubject += notificationObject.item_title;
            emailBody += '<div style="padding:10px;">';
            emailBody += sourceUser;
            emailBody += ' has assigned you an action item';
            emailBody += '</div>'
            break;
        case 'list_shared':
            emailSubject += notificationObject.list_title;
            emailBody += '<div style="padding:10px;">';
            emailBody += sourceUser;
            emailBody += ' has shared a list with you: ';
            emailBody += '<a href="' + SITE_URL + '#' + notificationObject.list_id + '">' + notificationObject.list_title + '</a>';
            emailBody += '</div>'
            break;
    }
    if (Meteor.isServer) {
        // This function only runs on server
        Email.send({
            from: emailFrom,
            bcc: recipients,
            subject: emailSubject,
            html: emailBody
        });
    }
}

上面的函数是在根目录下的一个JS文件(因此其代码可用于客户端和服务器)。但是当我在客户端代码中调用它时,没有任何反应。我的应用程序中包含电子邮件包。在我的本地机器(Windows 7)上,我没有 MAIL_URL 变量集。因此,调用 Email.send()函数应该在命令提示符下产生一个输出,但实际上没有输出。

The above function is in a JS file in the root (and so its code is available to both client and server). But when I call it in my client code, nothing happens. I have the email package included in my app. On my local machine (Windows 7), I don't have the MAIL_URL variable set. So calling the Email.send() function should ideally produce an output in command prompt, but nothing actually gets outputted.

在我们的生产服务器上,SMTP已正确安装,其他应用程序能够发送具有相同设置的电子邮件。我已经正确地配置了 MAIL_URL 环境变量,但仍然没有发送电子邮件。

On our production server, SMTP is properly setup and other applications are able to send emails with same settings. I've configured the MAIL_URL environment variable correctly there, but still no emails get sent.

有人可以告诉我如果我的代码有问题?有没有什么我不能正确的?

Could somebody tell me if there's a problem with my code? Is there anything I'm not doing correctly?

PS:我甚至尝试直接像下面的代码一样调用Email.send(),但是什么也没有发生。 / p>

P.S.: I even tried calling the Email.send() directly like in the code below, but still nothing happened.

if (Meteor.isServer) {
    Email.send({
        from: 'server@example.com',
        to: 'my-gmail-id@gmail.com',
        subject: 'This is a test email',
        html: '<b>Congrats, it works!</b>'
    });
}



    }
});


推荐答案

几乎与 Meteor的电子邮件未定义

请参阅此抽取请求用于示例代码。

只是为了澄清:Meteor不按顺序执行客户端和服务器代码。您必须对客户端与服务器上运行的内容进行更明确的说明。除了在JavaScript页面上进行线性执行方面的思考之外,还要考虑到每个流星代码都是由于事件而运行的。如果某段代码没有运行,那是因为没有触发它的事件。

Just to clarify: Meteor does not execute client and server code in sequence like that. You have to be more explicit about what is running on the client vs the server. Instead of thinking in terms of linear execution along the JavaScript page, think that each piece of Meteor code runs as a result of an event. If some piece of code is not running, it is because there is no event that triggered it.

这篇关于meteorjs:我正在使用Email.send()吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆