Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Signing emails with DKIM in Node.js

I'm writing a Nodejs app that needs to be able to send email. So far, I've used Postfix in conjunction with a Nodejs module called Nodemailer to send my email through Amazon SES.

Postfix has been handling the DKIM signing, but now I wish to get rid of postfix and just use Nodemailer to send emails through Amazon SES.

My only problem now is finding a way to sign emails within Nodejs. I've thought of running a opendkim command using "exec" in node but haven't been able to figure that out. From searching, there looks to be no modules for this either.

Can anyone help me on this?

like image 658
Ryan Avatar asked Mar 25 '12 03:03

Ryan


2 Answers

Latest version of Nodemailer supports DKIM signing out of the box, also tested with SES.

var transport = nodemailer.createTransport("SES", {
    AWSAccessKeyID: "AWSACCESSKEY",
    AWSSecretKey: "AWS/Secret/key"
});

// all messages sent with *transport* are signed with the following options
transport.useDKIM({
    domainName: "example.com",
    keySelector: "dkimselector",
    privateKey: fs.readFileSync("private_key.pem")
});

transport.sendMail(...);
like image 188
Andris Avatar answered Sep 24 '22 11:09

Andris


you can find at https://gist.github.com/2198497 an implementation I developped to dkim-sign mails sent through SES. It's heavily inspired by the php implementation by Ahmad Amarullah found here : http://code.google.com/p/php-mail-domain-signer/. I'm well aware the code is far from clean, but it should help you get started. The mails sent through it are considered correct by gmail and yahoo. Don't hesitate if you have questions / can't get it to work.

like image 20
Guitan Avatar answered Sep 21 '22 11:09

Guitan