"meteor deploy testcode" uses Mailgun. Instead, I want to use Gmail. A small test program like below works well on 'localhost:3000'. But it returns error on 'meteor.com':
Error invoking Method 'sendMail': Internal server error [500]
How to use Gmail properly?
(I set Gmail account permission lower, and test program on localhost can send a mail through 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 security check causes the error.
"Google account help" suggest 3 points. I did all of them and my code works as I expected.
Thank you.