Mail Reader
Read email via IMAP

HOST
IMAP mail server hostname, such as imap.gmail.com.
PORT
IMAP mail server port number, typically set to 993.
TLS/SSL
Whether the IMAP mail server requires TLS/SSL encryption.
USERNAME
The user name configured in the email server. The %FILENAME% variable can be included to insert the content of the TXT file with the filename named 'FILENAME' inside the workspace, achieving dynamic customization.
PASSWORD
Password for the account filled above. The %FILENAME% variable is also supported
MAILBOX
Mailbox name.
SINCE DAY(S) AGO
Read emails since how many days ago.
UNREAD ONLY
Choose whether to read unread emails only.
Input Object
Each element in the input object array represents each 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
Each object added to the output array represents a row of data in the output table. The object contains key-value pairs, where the key is the column header, and the value is the data for that column in the row. Once all the data is processed, the table will be output as a .csv file called 'output.csv' in the workspace.
// Output each text field from the read emails to a 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 the header field
output.header.push('from','subject','date')
API
Sychronous APIs are provided: api.files(), api.read(filename, encoding='utf8'), api.write(filename, text), api.rename(oldname, newname), api.remove(filename) to access files in workspace; and asynchronous APIs api.mail.moveto(uid, mailbox) and api.mail.remove(uid) are provided to mange mails.
// find mail with subject containing 'promote'
let mail = _.find(input, (m) => m.subject.includes('promote'))
// move the mail to 'Trash' mailbox
await api.mail.moveto(mail.uid, 'Trash')
// find mail with subject containing prize
mail = _.find(input, (m) => m.subject.includes('prize'))
// remove the mail
await api.mail.remove(mail.uid)
We are dedicated to improving our content. Please let us know if you come across any errors, including spelling, grammar, or other mistakes, as your feedback is valuable to us! 🤖️⚡️
Last updated