node-pgp-mail

Library to send PGP-encrypted and signed e-mails.

npm install node-pgp-mail
1 downloads in the last week
4 downloads in the last month

node-pgp-mail is a library to send PGP-encrypted e-mails. In the future, signing e-mails will also be supported.

Use the following code to initialise node-pgp-mail:

var pgpMail = require("node-pgp-mail");

var keyring; // node-pgp keyring object
var mailer = new pgpMail(keyring, "SENDMAIL", { "path": "/usr/sbin/sendmail" });

The second and third parameter define the mail transport method, see the Nodemailer docu for the syntax.

getMailRecipient()

Finds out one e-mail address to send an e-mail to the owner of the key. Prefers the one of the primary identity, but if that does not contain one, uses the one of an arbitrary other identity.

var keyId = "012345678ABCDEFAB"; // 16-digit uppercase hex long key ID
mailer.getMailRecipient(keyId, function(err, recipient) {
    if(err)
        ; // An error occurred

    // recipient is a string or null if none was found
});

sendEncryptedMail()

var to = "test@example.org";
var subject = "Test e-mail";
var body = "Test e-mail";
var toKeyId = "012345678ABCDEFAB"; // 16-digit uppercase hex long key ID to encrypt to
var headers = { "Reply-To": "test@example.com" }; // Optional additional e-mail headers
mailer.sendEncryptedMail(to, subject, body, toKeyId, function(err) {
    if(err)
        ; // An error occurred
}, headers);

sendMail()

Sends an unencrypted mail.

var to = "test@example.org";
var subject = "Test e-mail";
var body = "Test e-mail";
mailer.sendMail(to, subject, body, function(err) {
    if(err)
        ; // An error occurred
});

In order to specify additional headers, use a Mime object instead of a string as text.

Mime

For the e-mail body, instead of a string, you can also specify a Mime object:

var contentType = "text/plain";
var content = "Test e-mail";
var headers = { "Reply-To": "test@example.com" };
var transferEncoding = "quoted-printable";
var body = new pgpMail.Mime(contentType, content, headers, transferEncoding);

This also supports multipart messages by specifying an array as content:

var body = new pgpMail.Mime("multipart/mixed", [
    new pgpMail.Mime("text/plain", "Test part 1"),
    new pgpMail.Mime("text/plain", "Test part 2")
]);
npm loves you