Skip to content

Commit

Permalink
Updated DKIM support for Amazon SES
Browse files Browse the repository at this point in the history
  • Loading branch information
Andris Reinman committed Apr 3, 2012
1 parent 976a9de commit 92ea2ea
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 18 deletions.
14 changes: 0 additions & 14 deletions README.md
Expand Up @@ -279,20 +279,6 @@ Example:

See examples/example_dkim.js for a complete example.

#### DKIM Signing with Amazon SES

Amazon SES modifies Message-Id and Date fields of the message, so in order to use
DKIM signing you need to define appropriate `headerFieldNames` property where
Message-Id and Date fields are not listed (by default Message-Id and Date are
included as signed fields).

mailcomposer.useDKIM({
domainName: "node.ee",
keySelector: "dkim",
privateKey: fs.readFileSync("private_key.pem"),
headerFieldNames: "from:to:cc:bcc:subject:..." // but no Message-Id or Date!
});

### Well known services for SMTP

If you want to use a well known service as the SMTP host, you do not need
Expand Down
13 changes: 12 additions & 1 deletion examples/example_ses.js
@@ -1,4 +1,6 @@
var nodemailer = require('../lib/nodemailer');
var nodemailer = require('../lib/nodemailer'),
fs = require("fs"),
pathlib = require("path");

// Create an Amazon SES transport object
var transport = nodemailer.createTransport("SES", {
Expand All @@ -9,6 +11,15 @@ var transport = nodemailer.createTransport("SES", {

console.log('SES Configured');

// optional DKIM signing
/*
transport.useDKIM({
domainName: "do-not-trust.node.ee", // signing domain
keySelector: "dkim", // selector name (in this case there's a dkim._domainkey.do-not-trust.node.ee TXT record set up)
privateKey: fs.readFileSync(pathlib.join(__dirname,"test_private.pem"))
});
*/

// Message object
var message = {

Expand Down
2 changes: 1 addition & 1 deletion lib/nodemailer.js
Expand Up @@ -7,7 +7,7 @@ var Transport = require("./transport").Transport,
* Version constants
*/
var X_MAILER_NAME = "Nodemailer",
X_MAILER_VERSION = "0.3.13; +https://github.com/andris9/Nodemailer";
X_MAILER_VERSION = "0.3.14; +https://github.com/andris9/Nodemailer";

module.exports.X_MAILER_NAME = X_MAILER_NAME;
module.exports.X_MAILER_VERSION = X_MAILER_VERSION;
Expand Down
22 changes: 21 additions & 1 deletion lib/transport.js
Expand Up @@ -20,9 +20,10 @@ function Transport(type, options){

this.options = options;

this.transportType = (type || "").toString().trim().toUpperCase();
this.dkimOptions = false;

switch((type || "").toString().trim().toUpperCase()){
switch(this.transportType){
case "SMTP":
this.transport = new SMTPTransport(this.options);
break;
Expand Down Expand Up @@ -67,6 +68,25 @@ Transport.prototype.sendMailWithTransport = function(emailMessage, callback){
*/
Transport.prototype.useDKIM = function(dkim){
this.dkimOptions = dkim;

// SES doesn't like Message-Id and Date fields in DKIM signed data
if(this.dkimOptions && this.transportType == "SES"){
if(!this.dkimOptions.headerFieldNames){
this.dkimOptions.headerFieldNames = "From:Sender:Reply-To:Subject:To:" +
"Cc:MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID:" +
"Content-Description:Resent-Date:Resent-From:Resent-Sender:" +
"Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:" +
"List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post:" +
"List-Owner:List-Archive";
}else{
// remove Message-Id and Date field names if present in the list
this.dkimOptions.headerFieldNames = this.dkimOptions.headerFieldNames.
replace(/\:\s*(Message-Id|Date)\s*\:/ig, ":").
replace(/^\s*(Message-Id|Date)\s*\:/i, "").
replace(/\:\s*(Message-Id|Date)\s*$/i, "").
trim();
}
}
};

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "nodemailer",
"description": "Easy to use module to send e-mails, supports unicode and SSL/TLS",
"version": "0.3.13",
"version": "0.3.14",
"author" : "Andris Reinman",
"maintainers":[
{
Expand Down

0 comments on commit 92ea2ea

Please sign in to comment.