使用 Gmail 发送邮件的测试程序在 localhost:3000 上运行良好,但相同的代码在 meteor.com 上运行不佳
A test program to send mail using Gmail works well on localhost:3000, but the same code doesn't work on meteor.com
“流星部署测试代码”使用 Mailgun。相反,我想使用 Gmail。
像下面这样的小测试程序在 'localhost:3000' 上运行良好。
但 returns 错误 'meteor.com':
Error invoking Method 'sendMail': Internal server error [500]
如何正确使用Gmail?
(我把Gmail账号权限设置的比较低,localhost上的测试程序可以通过Gmail发邮件)
// test.html
<head>
<title>test</title>
</head>
<body>
{{> test}}
</body>
<template name="test">
<input type="button" value="send mail">
</template>
// test.js
if (Meteor.isClient) {
Template.test.events({
'click [type="button"]':function(){
var dateTime = new Date();
console.log(dateTime);
Meteor.call('sendMail',dateTime);
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
var gmailAccount = {'eml':'user@gmail.com','pwd':'************'};
var st = 'smtp://' + encodeURIComponent(gmailAccount.eml) + ':' + gmailAccount.pwd + '@smtp.gmail.com' + ':465/'; check(st,String);
process.env.MAIL_URL = st;
});
Meteor.methods({
'sendMail':function(dateTime){
var to = 'user@gmail.com'; check(to,String);
var from = 'user@gmail.com'; check(from,String);
var subject = 'test'; check(subject,String);
var text = 'Time:' + dateTime; check(text,String);
var sendObj = {'to':to, 'from':from, 'Reply-To':from, 'subject':subject, 'text':text};
Email.send(sendObj);
}
});
}
Gmail 安全检查导致错误。
"Google account help"建议3分。我完成了所有这些,并且我的代码按预期工作。
谢谢。
“流星部署测试代码”使用 Mailgun。相反,我想使用 Gmail。 像下面这样的小测试程序在 'localhost:3000' 上运行良好。 但 returns 错误 'meteor.com':
Error invoking Method 'sendMail': Internal server error [500]
如何正确使用Gmail?
(我把Gmail账号权限设置的比较低,localhost上的测试程序可以通过Gmail发邮件)
// test.html
<head>
<title>test</title>
</head>
<body>
{{> test}}
</body>
<template name="test">
<input type="button" value="send mail">
</template>
// test.js
if (Meteor.isClient) {
Template.test.events({
'click [type="button"]':function(){
var dateTime = new Date();
console.log(dateTime);
Meteor.call('sendMail',dateTime);
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
var gmailAccount = {'eml':'user@gmail.com','pwd':'************'};
var st = 'smtp://' + encodeURIComponent(gmailAccount.eml) + ':' + gmailAccount.pwd + '@smtp.gmail.com' + ':465/'; check(st,String);
process.env.MAIL_URL = st;
});
Meteor.methods({
'sendMail':function(dateTime){
var to = 'user@gmail.com'; check(to,String);
var from = 'user@gmail.com'; check(from,String);
var subject = 'test'; check(subject,String);
var text = 'Time:' + dateTime; check(text,String);
var sendObj = {'to':to, 'from':from, 'Reply-To':from, 'subject':subject, 'text':text};
Email.send(sendObj);
}
});
}
Gmail 安全检查导致错误。
"Google account help"建议3分。我完成了所有这些,并且我的代码按预期工作。
谢谢。