0.0.8 • Published 6 years ago
mail-receive v0.0.8
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 = require('mail-receive');
const imap = {
user: "mail@domain.com",
password: "pass",
host: "imap.hostimap.com",
port: 993,
tls: true,
tlsOptions: {
rejectUnauthorized: false
}
};
const n = MailReceive(imap);
n.on('end', () => console.log(`${imap.user} offline`))
.on('mail', mail =>
console.log(
mail.headers.get('subject'),
mail.from,
mail.textAsHtml
)
)
.on('connected', () => {
console.log(` ${imap.user} logged`)
})
.on('error', err => {
console.log(err)
})
.start()
Example subject
{
value:
[ { address: 'examplemail@hotmail.com', name: 'Juan Andres Rodriguez Arenas' } ],
html: '<span class="mp_address_group"><span class="mp_address_name">Juan Andres Rodriguez Arenas</span> <<a href="mailto:examplemail@hotmail.com" class="mp_address_email">examplemail@hotmail.com</a>></span>',
text: 'Juan Andres Rodriguez Arenas <examplemail@hotmail.com>'
}
<p>Body example</p>
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’)