cunneen:mailgun

v1.0.0Published 7 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Mailgun for Meteor

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

Setup Mailgun (if you haven't done so already)

  • 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.

Usage

in server/mailgun_config.js add:

1  Meteor.startup(function(){
2    Meteor.Mailgun.config({
3      username: 'YOUR_MAILGUN_USERNAME',
4      password: 'YOUR_MAILGUN_PASSWORD'
5    });
6  });
7
8  // In your server code: define a method that the client can call
9  Meteor.methods({
10    sendEmail: function (mailFields) {
11        console.log("about to send email...");
12        check([mailFields.to, mailFields.from, mailFields.subject, mailFields.text, mailFields.html], [String]);
13
14        // Let other method calls from the same client start running,
15        // without waiting for the email sending to complete.
16        this.unblock();
17
18        Meteor.Mailgun.send({
19            to: mailFields.to,
20            from: mailFields.from,
21            subject: mailFields.subject,
22            text: mailFields.text,
23            html: mailFields.html
24        });
25        console.log("email sent!");
26    }
27  });

Anywhere you want to send an email:

1
2  Meteor.call('sendEmail',{
3    to: 'whoItsTo@theDomain.com',
4    from: 'no-reply@where-ever.com',
5    subject: 'I really like sending emails with Mailgun!',
6    text: 'Mailgun is totally awesome for sending emails!',
7    html: 'With meteor it&apos;s easy to set up <strong>HTML</strong> <span style="color:red">emails</span> too.'
8  });

Special Thanks

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.