List headers

Nodemailer includes a helper for setting more complex List-* headers with ease. You can use this by providing message option list. It’s an object where key names are converted into list headers. List key help becomes List-Help header etc.

General rules

  • If the value is a string, it is treated as an URL
  • If you want to provide an optional comment, use {url:‘url’, comment: ‘comment’} object
  • If you want to have multiple header rows for the same List-* key, use an array as the value for this key
  • If you want to have multiple URLs for single List-* header row, use an array inside an array
  • List-* headers are treated as pregenerated values, this means that lines are not folded and strings are not encoded. Use only ascii characters and be prepared for longer header lines

Examples

1. Setup different List-* headers

let message = {
    from: [email protected]',
    to: [email protected]',
    subject: 'List Message',
    text: 'I hope no-one unsubscribes from this list!',
    list: {
        // List-Help: <mailto:[email protected]?subject=help>
        help: [email protected]?subject=help',
        // List-Unsubscribe: <http://example.com> (Comment)
        unsubscribe: {
            url: 'http://example.com',
            comment: 'Comment'
        },
        // List-Subscribe: <mailto:[email protected]?subject=subscribe>
        // List-Subscribe: <http://example.com> (Subscribe)
        subscribe: [
            [email protected]?subject=subscribe',
            {
                url: 'http://example.com',
                comment: 'Subscribe'
            }
        ],
        // List-Post: <http://example.com/post>, <mailto:[email protected]?subject=post> (Post)
        post: [
            [
                'http://example.com/post',
                {
                    url: [email protected]?subject=post',
                    comment: 'Post'
                }
            ]
        ]
    }
};