grunt-nodemailer

Grunt wrapper for Nodemailer

grunt-nodemailer

Grunt wrapper for Nodemailer

This plugin requires Grunt ~0.4.1

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-nodemailer --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-nodemailer');

In your project's Gruntfile, add a section named nodemailer to the data object passed into grunt.initConfig().

grunt.initConfig({
  nodemailer: {
    options: {
      // Task-specific options go here. 
    },
    your_target: {
      // Target-specific file lists and/or options go here. 
    },
  },
})

Type: Object Default value: null

A configuration object for an email transport. If left undefined or null, transport will default to 'sendmail' with default options.

The configuration object should have 2 properties:

  • type: Type of transport. Valid options are:
    • SMTP for using SMTP
    • SES for using Amazon SES
    • Sendmail for utilizing systems sendmail command
  • options: transport configuration options, see Nodemailer documentation for more info.

Type: Object Default value: {}

E-mail message configuration. See Nodemailer documentation for available options.

Type: Array Default value: []

A collection of recipients. Every item should have 2 properties:

  • name: Name of the recipient
  • email: E-mail address of the recipient

Note: Recipients specified here will be appended to those set in options.message.to.

See options.message for details.

See options.message for details.

See options.message for details.

See options.message for details.

BREAKING CHANGES: before v0.2 you had to provide 2 source files in order to pass HTML and text body message. Since v0.2 text files are automatically discovered. Keep reading for details.

Instead of providing text and html message options you may use external files by setting a src property on the sub-task. Accepted file extensions are .html, .htm and .txt.

If HTML files are provided, the task will look for .txt files with same filename to be used as text fallbacks.

Example:

nodemailer: {
  test: {
    options: { /* ... transport, message, etc ...*/},
    src: ['email-body.html']
  }
}
 
//Will use email-body.html for HTML email body, 
//optionally using email-body.txt (if found) as text fallback 

If multiple files are passed in, a message for each one will be delivered.

nodemailer: {
  test: {
    options: { /* ... transport, message, etc ...*/},
    src: ['email-body.html', 'email-body2.html']
  }
}
 
//Will send 2 messages 

Note: If HTML files include title tag it'll be used as the message subject.

Type: String Default value: null

Overrides src files set in the task configuration.

This configurations uses Gmail's SMTP service as transport.

By running the nodemailer:external task HTML body will be overridden.

grunt.initConfig({
  nodemailer: {
 
    options: {
      transport: {
        type: 'SMTP',
        options: {
          service: 'Gmail',
          auth: {
            user: 'john.doe@gmail.com',
            pass: 'password'
          }
        }
      },
      message: {
        subject: 'A test e-mail',
        text: 'Plain text message',
        html: '<body><h1>HTML custom message</h1></body>',
      },
      recipients: [
        {
          email: 'jane.doe@gmail.com',
          name: 'Jane Doe'
        }
      ]
    },
 
    inline: { /* use above options*/ },
 
    external: {
      src: ['email-body.html']
    }
  }
});

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

0.3.0 Added grunt cli option to override file src (thanks to @posabsolute)

0.2.1 Display error message instead of error name (fixes issue #3 thanks to @aszmyd)

0.2.0 - Task allows for multiple external sources to better comply to Grunt's file APIs. As of this version, you may set any supported Nodemailer message's option onto options.message. Added some tests.

0.1.2 - Replaced deprecated reference to grunt.util._ with lodash npm module

0.1.1 - Bugfix

0.1.0 - Initial release