email

Provides methods for working with email via IMAP.

getLastEmail

Retrieves last unseen email.

** Usage example:**

email.init('[YOUR_EMAIL]@gmail.com', 'password', 'imap.gmail.com', 993, true, 3000);
var mail = email.getLastEmail(60, 'email subject', 5000);
log.info(mail);

if(r.attachments && r.attachments.length > 0){
   const fs = require('fs');
   r.attachments.map((attachment) => {
   	let fileDescriptor;
   	try{
   		fileDescriptor = fs.openSync(attachment.filename, 'w');
   	} catch(e) {
   		throw 'could not open file: ' + e;
   	}
   	
   	try{
   		fs.writeFileSync(fileDescriptor, attachment.data);
   	} catch(e) {
   		throw 'error writing file: ' + e;
   	}
   	
   	fs.closeSync(fileDescriptor);
   });
}

Parameters:

Returns:

Object - Email body, text, textAsHtml, attachments if any, and TO, FROM, SUBJECT, DATE headers.

init

Set email connection details.

Parameters:

send

Send email using SMTP.

Parameters:

Last updated