A meteorite package for sending emails easily using Mailgun. Forked from David Brear's Sendgrid package.
To add this package to your application, run in your terminal:
meteor add cunneen:mailgun
- Visit Mailgun and create an account.
- Activate your account.
- Navigate to the Control Panel and Add a Custom Domain .
- I used a dedicated subdomain for Mailgun, but you can set it up with your primary domain if you like (if you don't already have email set up for your primary domain). Do not configure Receiving MX DNS records if you already have another provider handling inbound mail delivery.
- Update the DNS records for your domain as instructed by Mailgun
- From the Control Panel, Click on the domain you added.
- Under SMTP Authentication, make a note of your mailgun login and password.
- Fill in the usage below.
in server/mailgun_config.js
add:
Meteor.startup(function(){
Meteor.Mailgun.config({
username: 'YOUR_MAILGUN_USERNAME',
password: 'YOUR_MAILGUN_PASSWORD'
});
});
// In your server code: define a method that the client can call
Meteor.methods({
sendEmail: function (mailFields) {
console.log("about to send email...");
check([mailFields.to, mailFields.from, mailFields.subject, mailFields.text, mailFields.html], [String]);
// Let other method calls from the same client start running,
// without waiting for the email sending to complete.
this.unblock();
Meteor.Mailgun.send({
to: mailFields.to,
from: mailFields.from,
subject: mailFields.subject,
text: mailFields.text,
html: mailFields.html
});
console.log("email sent!");
}
});
Anywhere you want to send an email:
Meteor.call('sendEmail',{
to: '[email protected]',
from: '[email protected]',
subject: 'I really like sending emails with Mailgun!',
text: 'Mailgun is totally awesome for sending emails!',
html: 'With meteor it's easy to set up <strong>HTML</strong> <span style="color:red">emails</span> too.'
});
Thanks to @DavidBrear for the Sendgrid version (of which this is a fork). Thanks go out to @scottmotte for his help in figuring out how to do this without using the NPM module.