Skip to content

SMTP / IMAP / POP3 Email Activities

Version: 1.0.5  ·  ID: zoan-packages-smtp  ·  Author: Zoan Software

This package works with email by connecting directly to a server, without depending on an installed client. It works with any standard server that accepts a username and password: Gmail, your company’s mail server or your hosting provider’s.

ProtocolWhat forActivities
SMTPSend emailSMTP Send
IMAPRead and manage email (folders, read/unread, move, delete) — recommendedIMAP Read, IMAP Save Attachment, IMAP Mark Read, IMAP Move, IMAP Delete
POP3Basic reading (no folders or state) — only if there is no IMAPPOP3 Read, POP3 Delete

These activities do not keep a session: each one connects, signs in, does its work and disconnects. That is why each receives the server connection data. It is the same in all of them:

ParameterTypeDescription
hoststringServer (e.g. smtp.gmail.com, imap.gmail.com, pop.gmail.com).
portintPort. Defaults: SMTP 587, IMAP 993, POP3 995.
usernamestringUsername (usually the full email address).
passwordcredentialPassword or app password. In POP3 it is a string. See credentials.
securitystringConnection encryption: auto, none, ssl or starttls. Defaults: SMTP auto, IMAP and POP3 ssl.
ValueWhat it doesUsual ports
sslTLS from the first byte (implicitly encrypted connection).SMTP 465, IMAP 993, POP3 995
starttlsConnects in clear text and upgrades to TLS with STARTTLS; fails if the server does not offer it.SMTP 587, IMAP 143, POP3 110
autoChooses by port: direct TLS on the well-known SSL ports and STARTTLS on the others if the server offers it; if it does not, it continues unencrypted.—
noneNo encryption. Only for internal test servers.SMTP 25, IMAP 143, POP3 110

The value is case-insensitive; an unrecognized value is treated as the protocol default. The port does not change by itself when you change security: if you use ssl with SMTP, also set port = 465.

All activities sign in with username and password; SMTP servers that only accept unauthenticated sending are not supported.

ProviderSMTP (send)IMAP (read)POP3
Gmailsmtp.gmail.com : 587imap.gmail.com : 993pop.gmail.com : 995
Corporate serverYour IT team provides the server, port and encryption

Security: store the password in a credential

Section titled “Security: store the password in a credential”

Never write the password in plain text: store it in a Zoan Cloud credential. With a multi-field credential (for example user and password), the form that works in every activity of the package is:

username = credential("mail-bot")["user"]
password = credential("mail-bot")["password"]

In SMTP and IMAP the password field is of type credential, so it also accepts credential("mail-bot") directly (it takes the password field). In POP3 the field is plain text: always use the indexer: credential("mail-bot")["password"] (or ["value"] if the credential holds a single value). The value is not exposed in the playbook and is masked in the logs.

As in Outlook, IMAP Read (and POP3 Read) return a list of emails (ZoanMail). Each email has an identifier, its .Id, which you pass as mailId to the other activities to say which email to act on (save attachments, mark, move, delete):

  • In IMAP it is the message UID in its folder: stable across connections as long as the email stays in that folder.
  • In POP3 it is the message index in the mailbox (from 0): it changes when messages are deleted.
IMAP Read host = "imap.gmail.com" username = credential("mail-bot")["user"] password = credential("mail-bot")["password"]
unreadOnly = true → output: emails
For Each items = emails itemVariable = email
└─ activities:
IMAP Save Attachment ... mailId = email.Id outputPath = "C:/attachments"
IMAP Mark Read ... mailId = email.Id
PropertyTypeValue in IMAP / POP3
.IdstringUID (IMAP) or index (POP3), as text.
.SubjectstringSubject ("" if empty).
.FromstringAddress of the first sender, without the display name.
.To / .Ccstring[]Recipient addresses.
.Bccstring[]Always empty.
.BodystringPlain-text part; if the email only has HTML, the HTML.
.IsHtmlbooltrue only when the email has no text part and .Body is HTML.
.SentAtDateTimeDate from the message Date header (sent date).
.IsReadboolRead state in IMAP; always false in POP3.
.AttachmentsZoanAttachment[]With includeAttachments = true: name, MIME type and content of each attachment. Otherwise empty.

The full type is in Data types › ZoanMail.

ActivityTypeOutputWhat it does
SMTP Sendsmtp-send—Sends an email
ActivityTypeOutputWhat it does
IMAP Readimap-readList<ZoanMail>Reads emails with filters
IMAP Save Attachmentimap-save-attachment—Saves the attachments of an email
IMAP Mark Readimap-mark-read—Marks an email as read
IMAP Moveimap-move—Moves an email to another folder
IMAP Deleteimap-delete—Deletes an email
ActivityTypeOutputWhat it does
POP3 Readpop3-readList<ZoanMail>Reads emails (no folders or filters)
POP3 Deletepop3-delete—Deletes an email