gpt4 book ai didi

javascript - 调用meteor的Email.send时出现语法错误

转载 作者:行者123 更新时间:2023-11-27 23:56:47 27 4
gpt4 key购买 nike

我正在尝试使用meteor 和mailgun 设置电子邮件发送。之前,我使用了默认的 meteor 选项,如果部署了应用程序,则会发送电子邮件,因此方法本身应该没问题。问题是这个应用程序很可能在本地运行,所以我需要设置一个 smtp 服务器。我正在尝试使用提供的默认沙箱邮件枪,因为我还不知道我的域是什么,但突然我收到语法错误。这是 meteor 控制台所说的。不幸的是我无法理解这些。我的唯一代码出现在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)

我的问题在我更改 MAIL_URL 变量后开始:

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

该错误在 11:19 显示语法错误,在我的文件中是 .在电子邮件中发送

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
});
});
}

这是以寄存器形式调用此方法的示例:

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;

}
});

我正在使用 Meteor 文档中提到的确切方法,并且在更改 smtp 之前它就有效。

最佳答案

您的 from 参数必须采用正确的电子邮件地址格式(“******@****.**”)才能发送您的电子邮件。现在您正在提供“SentFrom”作为发件人地址!

看看the example再次:

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

关于javascript - 调用meteor的Email.send时出现语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32198022/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com