@mailchain/message-composer
v0.31.0
Published
Mailchain MIME message composer. RFC-5322 compliant
Downloads
525
Readme
Mailchain Message Composer
Warning
@mailchain/message-composer
library is in development and may not cover all cases yet. Use with caution.
RFC-5322 compliant MIME message composer for Node and for the browser. Just add the content you want and let the library take care of formatting it according to the specification.
Usage
const msg = createMessageComposer(messageComposerContext)
// .id('[email protected]') // Optional
.subject('Subject can contain UTF-8 chars including emojis 😉')
// .date(new Date('08/28/2022')) // Optional
.from({ name: 'Bob', address: '[email protected]' })
.recipients('To', { name: 'Alice', address: '[email protected]' })
.recipients('Cc', { name: 'Joe Doe', address: '[email protected]' })
.recipients(
'Bcc',
{ name: 'Jane Doe', address: '[email protected]' },
{ name: 'Bob', address: '[email protected]' },
)
.message('plain', Buffer.from('Plaintext content. Can also contain UTF-8 and emojis 🤐.'))
.message('html', Buffer.from('This is ✨rich-text✨ HTML <b>content</b>.'))
.attachment({
cid: 'bfcd3a31-646b-4dcd-a1ea-06d37baf7d2e',
contentType: 'image/png',
filename: 'mailchain-logo.png',
content: readFileSync('mailchain-logo.png'),
});
const { forSender, forVisibleRecipients, forBlindedRecipients } = await msg.build();
For full usage examples view the developer docs.
Installing
Using npm:
$ npm install @mailchain/message-composer
Using yarn:
$ yarn add @mailchain/message-composer