I’m working on a Meteor v1 application and trying to implement email functionality using the Email package with MailGun. However, when I try to send emails, I keep getting an Internal server error [500] when calling the sendEmail method.
Client-side code:
Template.ContactForm.events({
'submit .contact-form': function(evt, tmpl){
evt.preventDefault();
var departureCity = tmpl.find('#departure').value;
var destinationCity = tmpl.find('#destination').value;
var userEmail = tmpl.find('#email-input').value;
var fullName = tmpl.find('#name-input').value;
var phoneNumber = tmpl.find('#phone-input').value;
var additionalInfo = tmpl.find('#details-input').value;
Meteor.call('sendEmail', '[email protected]', userEmail, 'Quote Request', 'New quote request received.');
}
});
Server-side code:
Meteor.startup(function() {
var mailgunUser = "postmaster%40sandboxxxxxxxx.mailgun.org";
var mailgunPass = "xxxxxxxxxxx";
var smtpHost = "smtp.mailgun.org";
var smtpPort = "587";
process.env.MAIL_URL = 'smtp://' + encodeURIComponent(mailgunUser) + ':' + encodeURIComponent(mailgunPass) + '@' + encodeURIComponent(smtpHost) + ':' + smtpPort;
});
Meteor.methods({
'sendEmail': function (recipient, sender, emailSubject, emailBody) {
this.unblock();
Email.send({
to: recipient,
from: sender,
subject: emailSubject,
text: emailBody
});
}
});
The console shows: Error invoking Method ‘sendEmail’: Internal server error [500]
Has anyone encountered this problem before and knows how to resolve it?