Sometimes I need a quick and easy way to send emails using Mailgun. It takes a few minutes to configure this setup, but it's a one-time thing, and the code is portable.

Step 1 - Install Jake

JakeJS is a task management tool similar to Grunt or Gulp but inspired by Ruby Rake.

npm i -g jake

Step 2 - Create a New Project

Create a new directory.

mkdir ~/Desktop/my_new_project && ~/Desktop/my_new_project

Create a file.

touch email.jake
/* ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
Filename: Email Tester via Mailgun
Date: 3/31/17

* ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
var util = require('util');
var moment = require('moment');

namespace('email', function () {
	desc('Test E-mail. Ex: jake email:test');
	task('test', { async: true }, function() {
		var timestamp = moment().format("dddd, MMMM Do YYYY, h:mm:ss a");
		var apiKey   = "<ENTER YOUR MAILGUN API KEY>";
		var domain   = "mydomain.com";
		var fromName = "Excited User ";
		var from     =  fromName + "noreply@mydomain.com";
		var to       = "tester@maildrop.cc";
		var subject  = "E-mail Test";
		var message  = "Testing some Mailgun awesomness! \n" + timestamp;
		var cmds = [
			util.format("curl -s --user 'api:%s' https://api.mailgun.net/v3/%s/messages -F from='%s' -F to=%s -F subject='%s' -F text='%s'", 
				apiKey, domain, from, to, subject, message)
		];
		jake.exec(cmds, { printStdout: true });
	});	
});