Skip to content

A meteorite package for sending emails easily using Mailgun

Notifications You must be signed in to change notification settings

cunneen/meteor-mailgun

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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:

  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.

About

A meteorite package for sending emails easily using Mailgun

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%