简体   繁体   中英

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

I'm trying to set up email sending using meteor and 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. 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. 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.

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:

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 . in 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.

Your from argument has to be in a correct email address format ("******@****.**") in order for your email to be sent. Right now you are giving "SentFrom" as a sender address!

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.');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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