nodemailer-mailgun-transport ============================ [![Known Vulnerabilities](https://snyk.io/test/github/orliesaurus/nodemailer-mailgun-transport/badge.svg)](https://snyk.io/test/github/orliesaurus/nodemailer-mailgun-transport) ## What is this? nodemailer is an amazing node module to send emails within any of your nodejs apps. This is the transport plugin that goes with nodemailer to send email using [Mailgun](https://mailgun.com/)'s awesomeness! Pow Pow. ## How does it work? Based on [this mailgun-js module](https://github.com/1lobby/mailgun-js) and the [nodemailer module](https://github.com/andris9/Nodemailer), the Mailgun Transport was born. This is a transport layer, meaning it will allow you to send emails using nodemailer, using the Mailgun API instead of the SMTP protocol! Nodemailer allows you to write code once and then swap out the transport so you can use different accounts on different providers. On top of that it's a super solid way of sending emails quickly on your node app(s). The Mailgun transport for nodemailer is great to use when SMTP is blocked on your server or you just prefer the reliability of the web api! ## Support the project I know this is a tiny module but many people use it in production (high5 to all of us) - if you happen to use this module please click the star button - it means a lot to all the contributors ![](https://i.snag.gy/oef5di.jpg) ## Quickstart - Example Create a new file, install the dependencies **[1]** and look at the skeleton code below to get you started quickly! ```js const nodemailer = require('nodemailer'); const mg = require('nodemailer-mailgun-transport'); // This is your API key that you retrieve from www.mailgun.com/cp (free up to 10K monthly emails) const auth = { auth: { api_key: 'key-1234123412341234', domain: 'one of your domain names listed at your https://app.mailgun.com/app/sending/domains' } } const nodemailerMailgun = nodemailer.createTransport(mg(auth)); nodemailerMailgun.sendMail({ from: 'myemail@example.com', to: 'recipient@domain.com', // An array if you have multiple recipients. cc:'second@domain.com', bcc:'secretagent@company.gov', subject: 'Hey you, awesome!', 'replyTo': 'reply2this@company.com', //You can use "html:" to send HTML email content. It's magic! html: 'Wow Big powerful letters', //You can use "text:" to send plain-text content. It's oldschool! text: 'Mailgun rocks, pow pow!' }, (err, info) => { if (err) { console.log(`Error: ${err}`); } else { console.log(`Response: ${info}`); } }); ``` ## Buffer support Example: ```js const mailOptions = { ... attachments: [ { filename: 'text2.txt', content: new Buffer('hello world!','utf-8') }, ``` with encoded string as attachment content: ```js const mailOptions = { ... attachments: [ { filename: 'text1.txt', content: 'aGVsbG8gd29ybGQh', encoding: 'base64' }, ``` with encoded string as an inline attachment: ```js // Replace `filename` with `cid` const mailOptions = { ... attachments: [ { cid: 'logo.png', content: 'aGVsbG8gd29ybGQh', encoding: 'base64' }, ``` ```html ``` ## Address objects The "from", "to", "cc", and "bcc" fields support an address object or array of address objects. Each "name" and "address" are converted to ```"name
"``` format. "name" is optional, "address" is required. Missing or null address in object is skipped. Examples: ```js from: {name: 'Sales', address: 'sales@example.com'}, to: [{name:'Mary', address:'mary@differentexample.com'}, {address:'john@anotherexample.com'}] ``` is converted to: ```js from: 'Sales