open-index/open-npm huggingface dataset:
npm package: @jamton/nodemailer-mailgun-transport-ts
Description: Mailgun transport for the nodemailer library
Latest version: 1.0.0

## Installation

To use nodemailer-mailgun-transport, all you need to do is install the
`@jamton/nodemailer-mailgun-transport-ts` package

```sh
$ yarn add @jamton/nodemailer-mailgun-transport-ts

# or

$ npm i @jamton/nodemailer-mailgun-transport-ts
```

## Usage

```ts
import nodemailer from 'nodemailer';
import { MailgunTransport } from '@jamton/nodemailer-mailgun-transport-ts';

// This is your options that you retrieve from www.mailgun.com
const options = {
    auth: {
        domain: 'domain-name',
        api_key: '123456789',
    },
    host: 'api.mailgun.net',
};

const nodemailerMailgun = nodemailer.createTransport(new MailgunTransport(options));

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: '<b>Wow Big powerful letters</b>',
    //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}`);
    }
});
```
The "from", "to", "cc", and "bcc" fields support an address object or array of address objects. Each "name" and 
"address" are converted to ```"name <address>"``` format. "name" is optional, "address" is required. Missing or null 
address in object is skipped.

Example:
```ts
 from: {name: 'Sales', address: 'sales@example.com'},
 to: [{name:'Mary', address:'mary@differentexample.com'}, {address:'john@anotherexample.com'}]
```
Is converted to:
```ts
 from: 'Sales <sales@example.com>',
 to: 'Mary <mary@differentexample.com>,john@anotherexample.com'
```
To use consolidate.js templates locally, give the template key an object instead that contains a name key, an 
engine key and, optionally, a context object. For example, you can use Handlebars templates to generate the 
HTML for your message like so:
```ts
const contextObject = {
  variable1: 'value1',
  variable2: 'value2'
};

nodemailerMailgun.sendMail({
  from: 'myemail@example.com',
  to: 'recipient@domain.com', // An array if you have multiple recipients.
  subject: 'Hey you, awesome!',
  template: {
    name: 'email.hbs',
    engine: 'handlebars',
    context: contextObject
  }
}, (err, info) => {
  if (err) {
    console.log(`Error: ${err}`);
  }
  else {
    console.log(`Response: ${info}`);
  }
});
```