2.0.5 • Published 2 years ago
@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');
// Using the constructor
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());
// Results
/*
From: "First Last" <first.last@domain.com>
To: user@domain.com, "Someone Else" <someone.else@domain.com>
Subject: This is an example
List-Unsubscribe: <https://domain.com/unsubscribe?id=1>, <mailto:unsubscribe@domain.com>
List-Unsubscribe-Post: List-Unsubscribe=One-Click
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: base64
PGh0bWw+PGhlYWQ+PHRpdGxlPkVtYWlsPC90aXRsZT48L2hlYWQ+PGJvZHk+SGVsbG8gV29ybGQhPC9ib2R5Pg==
*/
IMailAddress
| Name | Type |
|---|
| address | string |
| name | string |
MailAddress
| Name | Type |
|---|
| address | string |
| name | string |
MailAddressList
| Name | Type |
|---|
| list | MailAddress[] |
| length | number |
add()
| Parameter | Type | Default | Description |
|---|
| address | string ¦ IMailAddress ¦ MailAddress | | |
remove()
| Parameter | Type | Default | Description |
|---|
| address | string ¦ IMailAddress ¦ MailAddress | | |
clear()
forEach()
| Parameter | Type | Default | Description |
|---|
| callbackFn | function(element: MailAddress, index: number, array: MailAddress[]) | | |
map()
| Parameter | Type | Default | Description |
|---|
| callbackFn | function(element: MailAddress) | | |
IHeaderUnsubscribeMailto
IHeaderUnsubscribePost
HeaderUnsubscribe
| Name | Type |
|---|
| list | string[] |
| length | number |
mailto
| Parameter | Type | Default | Description |
|---|
| address | string, IHeaderUnsubscribeMailto | | |
| subject | string | | |
post
| Parameter | Type | Default | Description |
|---|
| url | string, IHeaderUnsubscribePost | | |
| payload | string | | |
IAlternativePart
AlternativePart
constructor()
| Name | Type | Default | Description |
|---|
| content | string | | |
| contentType | string | text/html | |
| charset | string | utf-8 | |
| contentTransferEncoding | string | base64 | |
IMimeMessage
| Name | Type |
|---|
| 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
| Name | Type |
|---|
| from | string ¦ IMailAddress ¦ MailAddress |
| replyTo | string ¦ IMailAddress ¦ MailAddress |
| sender | string ¦ IMailAddress ¦ MailAddress |
| to | MailAddressList |
| cc | MailAddressList |
| bcc | MailAddressList |
| subject | string |
| alternatives | AlternativePart[] |
| unsubscribe | HeaderUnsubscribe |
setHeader()
| Name | Type | Default | Description |
|---|
| name | string | | |
| value | string | | |
setHTML()
| Name | Type | Default | Description |
|---|
| content | string | | |
| charset | string | utf-8 | |
| contentTransferEncoding | string | base64 | |
setText()
| Name | Type | Default | Description |
|---|
| content | string | | |
| charset | string | utf-8 | |
| contentTransferEncoding | string | base64 | |
toString()
Renders the MIME message.
| Parameter | Type | Default | Description |
|---|
| forceMultipartAlternative | boolean | false | Force the use of multipart/alternative content type when only 1 alternative has been added |