Skip to content

markhuge/node-mailgun-send

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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: '[email protected]',
  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="https://myapp.com/resetpassword?key=' + key + '">here</a> to reset your password'
  };

  mail.send(msg);

});

license

MIT

About

Send mail via mailgun

Resources

License

Stars

Watchers

Forks

Packages

No packages published