format-email-address

Format an email address before sending email to it

Downloads
1.7K
Stars
4

Format Email Address

Format an email address before sending email to it. Useful when sending emails with e.g. Amazon SES.

Will handle Q-encoding for you, so that unicode characters in the name part show up properly.

Installation

npm install --save format-email-address

Usage

const formatEmailAddress = require('format-email-address')

console.log(formatEmailAddress({ name: '', address: '[email protected]' }))
//=> [email protected]

console.log(formatEmailAddress({ name: 'John', address: '[email protected]' }))
//=> John <[email protected]>

console.log(formatEmailAddress({ name: 'John Smith', address: '[email protected]' }))
//=> John Smith <[email protected]>

console.log(formatEmailAddress({ name: 'Jack Sparrow, CPA', address: '[email protected]' }))
//=> "Jack Sparrow, CPA" <[email protected]>

console.log(formatEmailAddress({ name: 'Linus Unnebäck', address: '[email protected]' }))
//=> =?utf-8?Q?Linus_Unneb=C3=A4ck?= <[email protected]>