Skip to main content

Mail Reader

Connect to a mail server via IMAP protocol to read email. Mailbox configuration parameters depend on the email service or server being used.

Parameters

HOST - IMAP mail server hostname, e.g. imap.gmail.com.

PORT - IMAP mail server port number, default is the commonly used 993.

TLS/SSL - Whether the IMAP mail server requires TLS/SSL encryption.

USERNAME - The account name configured on the mail server. You can include the %FILENAME% variable to insert the content of a TXT file named FILENAME.txt from the working folder, enabling dynamic specification.

PASSWORD - The account password configured on the mail server. Supports the %FILENAME% variable.

MAILBOX - Mailbox name.

SINCE DAY(S) AGO - Read emails from the specified number of days ago.

UNREAD ONLY - Whether to read only unread emails.

No-Code Editor

Provides no-code commands such as "Reset output.csv" and "Filter emails". For example, filter emails from the @emily.tips domain with a subject containing Purchase Order, and write them to output.csv in the working folder.

Low-Code Editor

input Object Array

Each element in the input object array represents an email read from the specified mailbox:

// Print the subject and sender of each email read
input.forEach((mail) => {
console.log('from:' + mail.from + ', title:' + mail.subject)
})

output Object Array

Each object element added to the output array represents a row of data in the output table. The key in the object is the column header, and the value is the data for that column in this row. The table will ultimately be exported as an output.csv file in the working folder.

// Output the text fields of each email read to CSV, and save attachment files
input.forEach((mail) => {
output.push({
from: mail.from,
subject: mail.subject,
date: mail.date.toLocaleString(),
})

if (mail.attachments.length > 0) {
mail.attachments.forEach((att) => {
api.write(att.filename, att.content)
})
}
})

// Specify column headers
output.header.push('from','subject','date')

api Object

In addition to synchronous functions: api.files(), api.read(filename, encoding='utf8'), api.write(filename, text), api.rename(oldname, newname), api.remove(filename) for accessing files in the working folder, it also provides the mail object and related asynchronous functions api.mail.moveto(uid, mailbox), api.mail.remove(uid)

// Find the email with 'promotion' in the subject
let mail = _.find(input, (m) => m.subject.includes('promotion'))

// Move to the 'Trash' mail folder
await api.mail.moveto(mail.uid, 'Trash')

// Find the email with 'winning' in the subject
mail = _.find(input, (m) => m.subject.includes('winning'))

// Remove the email
await api.mail.remove(mail.uid)