使用mailGun在Meteor应用程序中发送电子邮件-调用方法“sendEmail”时出错
我使用Meteor v1构建un应用程序,为了能够从我的应用程序发送电子邮件,我添加了电子邮件包。 这是我在客户端的代码使用mailGun在Meteor应用程序中发送电子邮件-调用方法“sendEmail”时出错,meteor,compiler-errors,email,mailgun,Meteor,Compiler Errors,Email,Mailgun,我使用Meteor v1构建un应用程序,为了能够从我的应用程序发送电子邮件,我添加了电子邮件包。 这是我在客户端的代码 Template.Home.events({ 'click button': function(event, template){ event.preventDefault(); var depart = template.find('[id=exampleInputEmail1]').value; var ar
Template.Home.events({
'click button': function(event, template){
event.preventDefault();
var depart = template.find('[id=exampleInputEmail1]').value;
var arrive = template.find('[id=exampleInputPassword1]').value;
var email = template.find('[id=exampleInputPassword1m]').value;
var nom = template.find('[id=exampleInputPassword1s]').value;
var telephone = template.find('[id=exampleInputPassword1n]').value;
var element = template.find('[id=exampleInputPassword1j]').value;
Meteor.call('sendEmail', 'nwabdou85@yahoo.fr', email, 'Faites moi un devis rapide svp', 'This is a test of Email.send.');
}
});
服务器是
Meteor.startup(function() {
var username = "postmaster%40sandboxxxxxxxx.mailgun.org";
var password = "xxxxxxxxxxx";
var server = "smtp.mailgun.org";
var port = "587"
process.env.MAIL_URL = 'smtp://' + encodeURIComponent(username) + ':' + encodeURIComponent(password) + '@' + encodeURIComponent(server) + ':' + port;
});
// In your server code: define a method that the client can call
Meteor.methods({
'sendEmail': function (to, from, subject, text) {
// check([to, from, subject, text], [String]);
this.unblock();
Email.send({
to: to,
from: from,
subject: subject,
text: text
});
}
});
但是它不起作用!!它在控制台上抛出此错误:调用方法“sendmail”时出错:内部服务器错误[500]
你能解决这个问题吗?你能解决吗?我建议把你的主机切换到Heroku,它是免费的,但更具可配置性。试着阅读我最近关于这个主题的文章,应该会给你一些提示:。如果这是mailgun的500个错误,那么这是他们的错误,而不是你的错误。尝试访问mailgun上的仪表板,看看是否可以从那里获得一些信息。我花了一点时间试图把它弄对,这一切都是为了让邮件url正确 我记得在《防弹流星》中,你应该使用meteor.defer功能来延迟你的电子邮件发送过程。通常发送电子邮件会导致响应超时 同样,在这种情况下,this.unblock可能没有用处。如果第一种方法不起作用,请尝试对其进行注释。encodeURIcomponent将从sam@sam.com致sam%40sam.com
您的用户名已被URI编码,因此不需要进一步编码。在本例中,您对用户名进行了双重编码,因此可能由于身份验证错误而失败。是否检查了服务器日志?为什么不将MAIL_URL设置为真正的环境变量?你在哪里托管应用程序?对于前两个问题:我不知道怎么做;对于3:我把它放在meteor.com上:谢谢,我会的,但我的应用程序即使在本地,发送电子邮件也不起作用!!这个错误发生在控制台上,在Mailgun的日志中没有任何内容;老实说,我不知道如何使用meteor.defer,即使我在谷歌上搜索它,但我找不到有用的东西;然而,即使我没有改变任何事情,但它又起作用了:谢谢你的回答