流星JS:“邮件未发送;要启用发送,请设置MAIL_URL环境变量“

问题描述 投票:1回答:1

我收到以下邮件错误:

“邮件未发送;要启用发送,请设置MAIL_URL环境变量。”

不知道为什么。请帮忙。我仔细检查了邮件服务器是好的。试图从流星站点翻转:https://docs.meteor.com/environment-variables.html#MAIL-URL

但仍然得到错误。

我的代码在server文件夹中,这是config.js文件:

AWS.config.update({
    accessKeyId: Meteor.settings.private.s3Settings.awsAccessKeyId,
    secretAccessKey: Meteor.settings.private.s3Settings.awsSecretKey,
});
STS = new AWS.STS();

S3 = new AWS.S3();

Mailer.config({
    from: '[email protected]',
    replyTo: '[email protected]',
    addRoutes: false
});

Meteor.startup(() => {
    Mailer.init({
        templates: Templates
    });

    if (Meteor.isProduction) {
        process.env.MAIL_URL = 'smtp://export%40INSIDEDOMAIN.com:[email protected]:465/';
    }

    Meteor.call('check_users_trial', function(err) {
        if (err) {
            console.log(err);
        }
    });
});

SyncedCron.start();

Meteor.methods({
    check_users_trial: function() {
        function checkSubscriptions() {
            const fromDate = new Date(new Date().setDate(new Date().getDate() - 15)),
                toDate = new Date(new Date().setDate(new Date().getDate() - 13));

            const users = Accounts.users.find({
                'profile.isSubscribed': false,
                'profile.warningEmailSent': false,
                createdAt: {
                    $gt: fromDate,
                    $lt: toDate
                },
                roles: {
                    $ne: 'admin'
                }
            });

            users.forEach(function(user) {
                if (!user.profile.isSubscribed) {
                    let isSubscriptionValid = false;
                    const today = new Date();
                    const registerDate = new Date(user.createdAt);
                    const checkDate = registerDate.setDate(registerDate.getDate() + 14);

                    if (checkDate > today.getTime()) {
                        isSubscriptionValid = true;
                    }

                    if (!isSubscriptionValid) {
                        Meteor.call('send_warining_email_trial', user.emails[0].address, function(error) {
                            if (error) {
                                console.log(error);
                            } else {
                                Accounts.users.update({
                                    _id: user._id
                                }, {
                                    $set: {
                                        'profile.warningEmailSent': true
                                    }
                                });
                            }
                        });
                    }
                }
            });
        }

        SyncedCron.add({
            name: 'Send emails to users, whose trial period ended.',
            schedule: function(parser) {
                return parser.text('every 1 hours');
            },
            job: function() {
                checkSubscriptions();
            }
        });
    }
});
meteor
1个回答
3
投票

process.env.MAIL_URL只在startup()结束后才设定,这已经太晚了。 移动以下行

if (Meteor.isProduction) {
    process.env.MAIL_URL = 'smtp://export%40INSIDEDOMAIN.com:[email protected]:465/';
}

在你的Meteor.startup电话之上。并确保isProduction实际上是true,否则该代码将不会执行。

© www.soinside.com 2019 - 2024. All rights reserved.