Code Monkey home page Code Monkey logo

nodemailer-dkim's Introduction

DKIM Signer plugin for Nodemailer

This applies to Nodemailer v1.0+. Older versions have DKIM support built in.

Install

Install from npm

npm install nodemailer-dkim --save

Usage

Load the signer function

var signer = require('nodemailer-dkim').signer;

Attach it as a 'stream' handler for a nodemailer transport object

transporter.use('stream', signer(options))

Where

  • options is the DKIM options object
    • domainName is the domain name that is being used for signing
    • keySelector is the key selector (if you have set up a TXT record with DKIM public key at zzz._domainkey.blurdybloop.com then zzz is the selector)
    • privateKey is the private key that is used for DKIM signing (string)
    • headerFieldNames is an (optional) colon separated list of header fields to sign, by default all fields suggested by RFC4871 #5.5 are used

All messages transmitted through this transport objects are from now on DKIM signed.

NB! If several header fields with the same name exists, only the last one (the one in the bottom) is signed.

Example

var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport();
transporter.use('stream', require('nodemailer-dkim').signer({
    domainName: 'kreata.ee',
    keySelector: 'test',
    privateKey: fs.readFileSync('private.pem')
}));
transporter.sendMail({
    from: 'sender@address',
    to: 'receiver@address',
    subject: 'hello',
    text: 'hello world!'
}, function(err, response) {
    console.log(err || response);
});

Configration verification

You can use this module to check if your configuration is correct and the private key matches the public key listed in DNS

var verifyKeys = require('nodemailer-dkim').verifyKeys;
verifyKeys(options, callback);

Where

  • options is the same option object you use for the signer function
  • callback is the callback to run once verification is completed

Example

verifyKeys({
    domainName: 'kreata.ee',
    keySelector: 'test',
    privateKey: fs.readFileSync('private.pem')
}, function(err, success){
    if(err){
        console.log('Verification failed');
        console.log(err);
    }else if(success){
        console.log('Verification successful, keys match');
    }
});

License

MIT

nodemailer-dkim's People

Contributors

andris9 avatar jaittoka avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.