简体   繁体   English

调用流星的Email.send时出现语法错误

[英]Getting a syntax error when invoking meteor's Email.send

I'm trying to set up email sending using meteor and mailgun. 我正在尝试设置使用流星和Mailgun发送电子邮件。 Before, I used the default meteor options and if the app was deployed the emails were sent so the methods themself should be fine. 以前,我使用默认的“流星”选项,如果部署了该应用程序,则发送电子邮件,因此它们自己的方法应该很好。 The problem is this app will most likely be run locally so I need to set up an smtp server. 问题是此应用很可能会在本地运行,因此我需要设置一个smtp服务器。 I'm trying to use the default sandbox mailgun provided because I don't know what my domain will be yet but suddenly I'm getting a Syntax error. 我正在尝试使用提供的默认沙箱mailgun,因为我尚不知道我的域是什么,但突然我收到了语法错误。 Here's what the meteor console says. 这是流星控制台所说的。 Unfortunately I can't understand any of this. 不幸的是,我对此一无所知。 The only piece of my code appears in the meteor.methods. 我的代码只有一部分出现在meteor.methods中。

I20150825-08:50:51.482(2)? Exception while invoking method 'sendEmail' SenderError: Mail from command failed - 501 Syntax error
I20150825-08:50:51.484(2)?     at Object.Future.wait (/home/m/.meteor/packages/meteor-tool/.1.1.4.1ih17fx++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:398:15)
I20150825-08:50:51.484(2)?     at smtpSend (packages/email/email.js:76:1)
I20150825-08:50:51.484(2)?     at Object.Email.send (packages/email/email.js:153:1)
>I20150825-08:50:51.485(2)?     at [object Object].Meteor.methods.sendEmail (app/server/methods.js:11:19)
I20150825-08:50:51.485(2)?     at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1617:1)
I20150825-08:50:51.485(2)?     at packages/ddp/livedata_server.js:648:1
I20150825-08:50:51.485(2)?     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20150825-08:50:51.485(2)?     at packages/ddp/livedata_server.js:647:1
I20150825-08:50:51.485(2)?     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20150825-08:50:51.485(2)?     at [object Object]._.extend.protocol_handlers.method (packages/ddp/livedata_server.js:646:1)
I20150825-08:50:51.485(2)?     - - - - -
I20150825-08:50:51.486(2)?     at SMTPClient._actionMAIL (/home/m/.meteor/packages/email/.1.0.6.1rj8k8w++os+web.browser+web.cordova/npm/node_modules/simplesmtp/lib/client.js:879:23)
I20150825-08:50:51.486(2)?     at SMTPClient._onData (/home/m/.meteor/packages/email/.1.0.6.1rj8k8w++os+web.browser+web.cordova/npm/node_modules/simplesmtp/lib/client.js:329:29)
I20150825-08:50:51.486(2)?     at CleartextStream.emit (events.js:95:17)
I20150825-08:50:51.486(2)?     at CleartextStream.<anonymous> (_stream_readable.js:765:14)
I20150825-08:50:51.486(2)?     at CleartextStream.emit (events.js:92:17)
I20150825-08:50:51.486(2)?     at emitReadable_ (_stream_readable.js:427:10)
I20150825-08:50:51.486(2)?     at _stream_readable.js:420:7
I20150825-08:50:51.486(2)?     at process._tickCallback (node.js:442:13)

My problem started after I changed the MAIL_URL variable: 更改MAIL_URL变量后,我的问题开始了:

process.env.MAIL_URL = 'smtp://postmaster%40SANDBOX:PASSWORD@smtp.mailgun.org:587';

The error shows a syntax error at 11:19 which in my file is the . 该错误在11:19显示语法错误,在我的文件中是。 in Email.send 在Email.send中

if (Meteor.isServer) {
Meteor.startup(function () {
    process.env.MAIL_URL = 'smtp://postmaster%40SANDBOX:PASSWORD@smtp.mailgun.org:587';
});
Meteor.methods({
    sendEmail: function (to, from, subject, text) {
        check([to, from, subject, text], [String]);
        // Let other method calls from the same client start running,
        // without waiting for the email sending to complete.
        this.unblock();
        Email.send({
            to: to,
            from: from,
            subject: subject,
            text: text
        });
    });
}

This is an example call for this method in a register form: 这是一个以寄存器形式对此方法的示例调用:

Template.register.events({
'submit form': function (event) {
    event.preventDefault();

    var rEmail = $('[id=registerEmail]').val();
    var rPassword = $('[id=registerPassword]').val();
    var passwordConfirm = $('[id=passwordConfirm]').val();
    var rName = $('#registerName').val();
    var rSurname = $('#registerSurname').val();

    if (isEmail(rEmail) && areValidPasswords(rPassword, passwordConfirm)) {


        var idUser = Accounts.createUser({
            email: rEmail,
            password: rPassword,
            profile: {
                'name': rName,
                'surname': rSurname
            }
        }, function (error) {
            if (error) {
                window.alert(error.reason);
            } else {
                Router.go("home");
            }
        }
        );
        Meteor.call('sendEmail',rEmail,'SentFrom','Subject','Content');
        Meteor.setTimeout(function(){Router.go('dashboard')}, 2000);
    }
    else
        return false;

  }
});

I'm using the exact method mentioned in the Meteor docs and it worked before changing the smtp. 我使用的是Meteor文档中提到的确切方法,并且在更改smtp之前有效。

Your from argument has to be in a correct email address format ("******@****.**") in order for your email to be sent. 您的from参数必须采用正确的电子邮件地址格式(“ ******@****.**”),以便发送电子邮件。 Right now you are giving "SentFrom" as a sender address! 现在,您将“ SentFrom”作为发件人地址!

Have a look at the example again: 再看一个例子

Meteor.call('sendEmail',
            'alice@example.com',
            'bob@example.com',
            'Hello from Meteor!',
            'This is a test of Email.send.');

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

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