mailgun-send

Send mail via mailgun

Usage no npm install needed!

<script type="module">
  import mailgunSend from 'https://cdn.skypack.dev/mailgun-send';
</script>

README

mailgun-send Code Climate Dependency Status

Send mail via mailgun

NOTE: Mailgun changed their API

If you are using < v1.0 of this library there are breaking changes due to the changes in the mailgun api.

install

With npm do:

npm install mailgun-send

usage

const mail   = require('mailgun-send');
const domain = "myapp.com";
const key    = "<mailgun api key>"

mail.config({
  key: key,
  domain: domain,
  sender: `noreply@${domain}`
});

mail.send({
  subject: 'hello from myapp!',
  recipient: 'user@email.com',
  body: 'This is an email from myapp'
});

mail.config()

properties:

  • key - Mailgun API key (required)
  • sender - optional default sender
  • recipient - optional default recipient
  • subject - optional default subject
  • body - optional default body

Defaults (except the API key) can be overriden on every send.

mail.send()

Send the msg.

practical example

Implement a password reset scheme...


// Password reset feature
app.post('/forgotPassword', function (req,res) {
  key = getTempPasswordResetKey();

  var msg = {
    subject: 'Password reset confirmation',
    recipient: req.body.email
    body: 'Click <a href="http://myapp.com/resetpassword?key=' + key + '">here</a> to reset your password'
  };

  mail.send(msg);

});

license

MIT