Home

Awesome

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)

Usage

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: 'whoItsTo@theDomain.com',
    from: 'no-reply@where-ever.com',
    subject: 'I really like sending emails with Mailgun!',
    text: 'Mailgun is totally awesome for sending emails!',
    html: 'With meteor it&apos;s easy to set up <strong>HTML</strong> <span style="color:red">emails</span> too.'
  });

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.