@evokegroup/mime
import { MimeMessage } from '@evokegroup/mime';
const message = new MimeMessage();
message.from = { address: 'first.last@domain.com', name: 'First Last' };
message.subject = 'This is an example';
message.to.add('user@domain.com');
message.to.add({ address: 'someone.else@domain.com', name: 'Someone Else' });
message.setHTML('<html><head><title>Email</title></head><body>Hello World!</body>');
message.unsubscribe.mailto('unsubscribe@domain.com');
message.unsubscribe.post('https://domain.com/unsubscribe?id=1');
const message = new MimeMessage({
from: { address: 'first.last@domain.com', name: 'First Last' },
subject: 'This is an example',
to: ['user@domain.com', { address: 'someone.else@domain.com', name: 'Someone Else' }],
content: '<html><head><title>Email</title></head><body>Hello World!</body>',
headers: {
'List-Unsubscribe': '<https://domain.com/unsubscribe?id=1>, <mailto:unsubscribe@domain.com>',
'List-Unsubscribe-Post': 'List-Unsubscribe=One-Click'
}
});
console.log(message.toString());
IMailAddress
| address | string |
| [name] | string |
MailAddress
MailAddressList
| list | MailAddress[] |
| length | number |
add()
| address | string ¦ IMailAddress ¦ MailAddress | | |
remove()
| address | string ¦ IMailAddress ¦ MailAddress | | |
clear()
forEach()
| callbackFn | function(element: MailAddress, index: number, array: MailAddress[]) | | |
map()
| callbackFn | function(element: MailAddress) | | |
| address | string |
| [subject] | string |
mailto
| address | string, IHeaderUnsubscribeMailto | | |
| [subject] | string | | |
post
| url | string, IHeaderUnsubscribePost | | |
| [payload] | string | | |
IAlternativePart
| content | string |
| [contentType] | string |
| [charset] | string |
| [contentTransferEncoding] | string |
AlternativePart
| content | string |
| [contentType] | string |
| [charset] | string |
| [contentTransferEncoding] | string |
constructor()
| content | string | | |
| contentType | string | text/html | |
| charset | string | utf-8 | |
| contentTransferEncoding | string | base64 | |
IMimeMessage
| [from] | string ¦ IMailAddress ¦ MailAddress |
| [replyTo] | string ¦ IMailAddress ¦ MailAddress |
| [sender] | string ¦ IMailAddress ¦ MailAddress |
| [to] | (string ¦ IMailAddress ¦ MailAddress)[] |
| [cc] | (string ¦ IMailAddress ¦ MailAddress)[] |
| [bcc] | (string ¦ IMailAddress ¦ MailAddress)[] |
| [subject] | string |
| [alternatives] | IAlternativePart[] ¦ AlternativePart[] |
| [headers] | Record<string, string> |
MimeMessage
| from | string ¦ IMailAddress ¦ MailAddress |
| replyTo | string ¦ IMailAddress ¦ MailAddress |
| sender | string ¦ IMailAddress ¦ MailAddress |
| to | MailAddressList |
| cc | MailAddressList |
| bcc | MailAddressList |
| subject | string |
| alternatives | AlternativePart[] |
| unsubscribe | HeaderUnsubscribe |
setHTML()
| content | string | | |
| charset | string | utf-8 | |
| contentTransferEncoding | string | base64 | |
setText()
| content | string | | |
| charset | string | utf-8 | |
| contentTransferEncoding | string | base64 | |
toString()
Renders the MIME message.
| forceMultipartAlternative | boolean | false | Force the use of multipart/alternative content type when only 1 alternative has been added |