emailtools
v0.0.12
Published
Node JS set of tools to ease working with Email protocols
Downloads
2
Readme
EmailTools
Set of NodeJS functions to make working with emails easier. Please do not expect any sophisticated logic the main goal is to keep it simple and straightforward to use. This module serves as an abstraction layer on top of several great modules for working different email protocols.
- EmailTools
- .SMTP
- .connect(options) ⇒ Object
- .test(options) ⇒ Promise
- .send(options) ⇒ Promise
- .IMAP
- .connect(options) ⇒ Imap
- .test(options) ⇒ Promise
- .getFolders(options) ⇒ Promise
- .getFolderInfo(options) ⇒ Promise
- .getLastMessagesHeaders(options) ⇒ Promise
- .searchMessageHeaders(options) ⇒ Promise
- .readMessage(options) ⇒ Promise
- .readMessages(options) ⇒ Promise
- .appendMessage(options) ⇒ Promise
- .template(inputText, vars) ⇒ string
- .SMTP
EmailTools.SMTP
Provides all the SMTP functions.
Kind: static property of EmailTools
- .SMTP
- .connect(options) ⇒ Object
- .test(options) ⇒ Promise
- .send(options) ⇒ Promise
SMTP.connect(options) ⇒ Object
Establish SMTP connection to host
Kind: static method of SMTP
Returns: Object - SMTP connection instance as returned from nodemailer
| Param | Type | Description | | --- | --- | --- | | options | Object | Connection options | | options.user | string | SMTP account user | | options.password | string | SMTP account password | | options.host | string | SMTP host server | | options.port | string | SMTP host server port | | options.tls | tls | SMTP TLS connection flag |
SMTP.test(options) ⇒ Promise
Test SMTP connection
Kind: static method of SMTP
Returns: Promise - Resolved on success and rejected on failure
| Param | Type | Description | | --- | --- | --- | | options | Object | | | options.connection | Object | Input options passed to connect() to establish the connection with host |
SMTP.send(options) ⇒ Promise
Send email
Kind: static method of SMTP
Returns: Promise - Resolved on success and rejected on failure
| Param | Type | Description | | --- | --- | --- | | options | Object | | | options.connection | Object | Input options passed to connect() to establish the connection with host | | options.templateVars | Object | If provided the template() function is applied to Subject and HTML | | options.data | Object | Email message definition | | options.data.from | string | Object | Either string of sender or object having name and address attributes | | options.data.to | string | Array | Comma seperated or an Array of recipients | | options.data.cc | string | Array | Comma seperated or an Array of recipients | | options.data.bcc | string | Array | Comma seperated or an Array of recipients | | options.data.subject | string | The subject of the email | | options.data.html | string | Actual message send as html (automatically converted and added to a text field) |
EmailTools.IMAP
Provides all the IMAP functions.
IMAP connection is established automatically upon every function call. This is as designed since nature of application this module was originally developed wouldn't allow to keep connection alive. This behaviour might be extended in the future to keep connection alive using a flag.
Kind: static property of EmailTools
- .IMAP
- .connect(options) ⇒ Imap
- .test(options) ⇒ Promise
- .getFolders(options) ⇒ Promise
- .getFolderInfo(options) ⇒ Promise
- .getLastMessagesHeaders(options) ⇒ Promise
- .searchMessageHeaders(options) ⇒ Promise
- .readMessage(options) ⇒ Promise
- .readMessages(options) ⇒ Promise
- .appendMessage(options) ⇒ Promise
IMAP.connect(options) ⇒ Imap
Establish IMAP connection to host
Kind: static method of IMAP
Returns: Imap - IMAP connection instance as returned from node-imap
| Param | Type | Description | | --- | --- | --- | | options | Object | Connection options | | options.user | string | IMAP account user | | options.password | string | IMAP account password | | options.host | string | IMAP host server | | options.port | string | IMAP host server port | | options.tls | tls | IMAP TLS connection flag |
IMAP.test(options) ⇒ Promise
Test IMAP connection
Kind: static method of IMAP
Returns: Promise - Resolved on success and rejected on failure
| Param | Type | Description | | --- | --- | --- | | options | Object | | | options.connection | Object | Input options passed to connect() to establish the connection with host |
IMAP.getFolders(options) ⇒ Promise
Get whole folder structure for provided IMAP account. Format of the structure is defined by the flags described below - If no flag is set returned format is a string array containing folder identifiers.
Kind: static method of IMAP
Returns: Promise - Resolved with structure defined by the flags above
| Param | Type | Description | | --- | --- | --- | | options | Object | | | options.connection | Object | Input options passed to connect() to establish the connection with host | | options.jstree | boolean | If true returned structure is compatible with a jsTree module | | options.raw | boolean | If true returned as received from node-imap |
IMAP.getFolderInfo(options) ⇒ Promise
Get folder information for provided IMAP account
Kind: static method of IMAP
Returns: Promise - Resolved with the folder IMAP information
| Param | Type | Description | | --- | --- | --- | | options | Object | | | options.connection | Object | Input options passed to connect() to establish the connection with host | | options.folderName | Object | Name of the folder |
IMAP.getLastMessagesHeaders(options) ⇒ Promise
Get headers of latest messages of specified folder for provided account. Number of messages is defined by the length flag.
Seqno is used to sort emails not UID.
Kind: static method of IMAP
Returns: Promise - Resolved with dictionary where Sequence number is used as key and header object as value
| Param | Type | Description | | --- | --- | --- | | options | Object | | | options.connection | Object | Input options passed to connect() to establish the connection with host | | options.folderName | string | Valid folder name for given IMAP account | | options.length | int | Number of messages returned |
IMAP.searchMessageHeaders(options) ⇒ Promise
Search FROM and TO
Kind: static method of IMAP
Returns: Promise - Resolved with dictionary where Sequence number is used as key and header object as value
| Param | Type | Description | | --- | --- | --- | | options | Object | | | options.connection | Object | Input options passed to connect() to establish the connection with host | | options.folderName | string | Valid folder name for given IMAP account | | options.search | string | Phrase to search for |
IMAP.readMessage(options) ⇒ Promise
Read and parse message specified by folder name and sequence number.
Kind: static method of IMAP
Returns: Promise - Resolved with MailParser message object
| Param | Type | Description | | --- | --- | --- | | options | Object | | | options.connection | Object | Input options passed to connect() to establish the connection with host | | options.folderName | string | Valid folder name for given IMAP account | | options.messageSeqNo | int | Message sequence number with the folder |
IMAP.readMessages(options) ⇒ Promise
Read and parse messages specified by folder name and sequence number range
Kind: static method of IMAP
Returns: Promise - Resolved with MailParser message object
| Param | Type | Description | | --- | --- | --- | | options | Object | | | options.connection | Object | Input options passed to connect() to establish the connection with host | | options.folderName | string | Valid folder name for given IMAP account | | options.seqNoRange | Array.<int> | Sequence number range FROM, TO |
IMAP.appendMessage(options) ⇒ Promise
(NOT IMPLEMENTED) Appends message to the given folder of given account
Kind: static method of IMAP
| Param | Type | Description | | --- | --- | --- | | options | Object | | | options.connection | Object | Input options passed to connect() to establish the connection with host | | options.folderName | string | Valid folder name for the given IMAP account | | options.email | Object | Email object which shall be parsed and appended |
EmailTools.template(inputText, vars) ⇒ string
All the text within %?% entries is replaced with a value from matching keys from vars
Kind: static method of EmailTools
| Param | Type | Description | | --- | --- | --- | | inputText | string | Input text used as a template | | vars | Object | Variables used to replace template entries |