@evokegroup/mime
v2.0.5
Published
```javascript import { MimeMessage } from '@evokegroup/mime';
Downloads
235
Keywords
Readme
@evokegroup/mime
import { MimeMessage } from '@evokegroup/mime';
const message = new MimeMessage();
message.from = { address: '[email protected]', name: 'First Last' };
message.subject = 'This is an example';
message.to.add('[email protected]');
message.to.add({ address: '[email protected]', name: 'Someone Else' });
message.setHTML('<html><head><title>Email</title></head><body>Hello World!</body>');
message.unsubscribe.mailto('[email protected]');
message.unsubscribe.post('https://domain.com/unsubscribe?id=1');
// Using the constructor
const message = new MimeMessage({
from: { address: '[email protected]', name: 'First Last' },
subject: 'This is an example',
to: ['[email protected]', { address: '[email protected]', name: 'Someone Else' }],
content: '<html><head><title>Email</title></head><body>Hello World!</body>',
headers: {
'List-Unsubscribe': '<https://domain.com/unsubscribe?id=1>, <mailto:[email protected]>',
'List-Unsubscribe-Post': 'List-Unsubscribe=One-Click'
}
});
// ----
console.log(message.toString());
// Results
/*
From: "First Last" <[email protected]>
To: [email protected], "Someone Else" <[email protected]>
Subject: This is an example
List-Unsubscribe: <https://domain.com/unsubscribe?id=1>, <mailto:[email protected]>
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
| Name | Type |
| ---- | ---- |
| address | string
|
| [subject] | string
|
IHeaderUnsubscribePost
| Name | Type |
| ---- | ---- |
| url | string
|
| [payload] | string
|
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
| Name | Type |
| ---- | ---- |
| content | string
|
| [contentType] | string
|
| [charset] | string
|
| [contentTransferEncoding] | string
|
AlternativePart
| Name | Type |
| ---- | ---- |
| content | string
|
| [contentType] | string
|
| [charset] | string
|
| [contentTransferEncoding] | string
|
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 |