Mail receive
Imap tool for receiving asynchronous mails
Dependencies
Lib | Version |
---|---|
debug | ^3.1.0 |
events | ^2.0.0 |
imap | ^0.8.19 |
mailparser | ^2.2.0 |
util | ^0.10.3 |
Install
npm install mail-receive -S
Usage
Simple use
const MailReceive = ;const imap =user: "mail@domain.com"password: "pass"host: "imap.hostimap.com"port: 993tls: truetlsOptions:rejectUnauthorized: false;const n = ;nstart
Example subject
Event Handler
- start() = Start the imap connection
- stop() = Close the imap connection
Events On()
- .on('connected', () => { console.log('IMAP connected') } )
- .on("mail', mail => { console.log(mail) } )
- .on("error', err => { console.log(err) } )
- .on("end', () => { console.log('IMAP close') } )
Mail object
Parsed mail* object has the following properties
- subject (also available from the header mail.headers.get(‘subject’))
- from is an address object for the From: header
- to is an address object for the To: header
- cc is an address object for the Cc: header
- bcc is an address object for the Bcc: header (usually not present)
- date is a Date object for the Date: header
- messageId is the Message-ID value string
- inReplyTo is the In-Reply-To value string
- reply-to is an address object for the Cc: header
- references is an array of referenced Message-ID values
- html is the HTML body of the message. If the message included embedded images as cid: urls then these are all replaced with base64 formatted data: URIs
- text is the plaintext body of the message
- textAsHtml is the plaintext body of the message formatted as HTML
- attachments is an array of attachments
- address object
- Address objects have the following structure:
Value an array with address details
- name: name part of the email/group
- address: email address
- group: array of grouped addresses
- text: formatted address string for plaintext context
- html: formatted address string for HTML context
Headers
mail.headers.get('example')
- from
- subject
- to
- cc
- bcc
- sender
- reply-to
- delivered-to
- return-path
- priority ( ‘high’, ‘normal’, ‘low’)