Skip to content

IMAP server (imap) ​

Connects to an IMAP server, checks its greeting, optionally protects the connection and signs in, and measures how long that takes. With a mailbox named it also reports how many messages the mailbox holds.

What it looks like ​

The page of a imap sensor in the light theme

The page of an IMAP sensor after a few polls, over TLS, signed in and counting the messages of a mailbox on a lab server. In the dark theme: the sensor's page. The form for adding it, with its parameters filled in: light, dark.

Channels ​

KeyNameUnitDefault limits
connect_msConnect timemswarning above 1000, error above 3000
response_msResponse time (connecting, TLS and signing in)mswarning above 2000, error above 5000
messagesMessages in the mailbox (with mailbox)none
cert_days_remainingDays until the certificate expires (with TLS)dayswarning below 21, error below 7
chain_days_remainingDays until the earliest expiry in the chain (with TLS)dayswarning below 21, error below 7

The certificate is read from the connection the sensor itself made, also when it is untrusted and the sensor runs with verify_tls off or a pin; an expired certificate that is accepted that way makes the sensor Down, as for the HTTP sensors.

Parameters ​

ParameterDefaultMeaning
port143, or 993 with security tlsTCP port.
securitynonenone, starttls (the connection is upgraded after the greeting; the sensor fails if the server does not offer it, so a downgrade is noticed) or tls (TLS from the first byte, on the dedicated port).
authenticatefalseSign in with the login credential. Refused without starttls or tls unless allow_plaintext_login is set, because the password would cross the network in the clear.
allow_plaintext_loginfalseAllow authenticate on an unprotected connection, for a network you trust.
verify_tlstrueVerify the server certificate against the system trust store. See pinning a certificate for the alternative to turning it off.
tls_fingerprintnoneTrust exactly the one certificate with this SHA-256 fingerprint, whatever its chain, dates or name say. Needs starttls or tls. A different certificate is refused with both fingerprints in the message.
server_namethe device's host name, else its addressThe name sent to the server (SNI) and checked against the certificate. Set it when the device is added by address and the certificate carries a name.
check_certificatetrueWith TLS, report how long the certificate lasts.
expect_bannernoneRequire the greeting to contain this text. A greeting without it makes the sensor Down.
mailboxnoneReport how many messages this mailbox holds (INBOX). ASCII names only. Needs authenticate. Read with STATUS, so nothing is marked as read.

Suggested interval: 60 seconds. Credential: an optional login credential, used when authenticate is on. Sign-in uses AUTHENTICATE PLAIN when the server offers it with SASL-IR, otherwise LOGIN; a server that announces LOGINDISABLED is not sent the password.

On the target ​

An account that can read the mailbox. Nothing is changed.

Failures ​

MessageMeaning
a refused connection (kind unreachable), a timeout (kind timeout)The service is not listening, or a firewall drops the traffic.
... did not greet like an IMAP server (kind protocol)Something else answers on that port.
the server does not offer STARTTLS ..., TLS error: ...As for SMTP.
the server rejected the login: [AUTHENTICATIONFAILED] ... (kind auth_failed)The user name or password is wrong.
IMAP could not look at mailbox ... (kind protocol)The mailbox does not exist or the account may not read it.

Testing ​

The live tests in crates/probeward-sensors/tests/mail_ftp_live.rs run against a real mail server when these variables are set, and print one line and return when they are not:

VariableMeaning
PROBEWARD_TEST_MAIL_HOSTThe server's address.
PROBEWARD_TEST_MAIL_NAMEThe name its certificate carries, sent as the TLS server name.
PROBEWARD_TEST_MAIL_USER, PROBEWARD_TEST_MAIL_PASSWORDAn account on it.
PROBEWARD_TEST_MAIL_ADDRESSThat account's mail address.
PROBEWARD_TEST_MAIL_CA_FILEThe PEM file of the authority that issued the certificate.
sh
cargo test -p probeward-sensors --test mail_ftp_live -- --nocapture

The protocol steps themselves (STARTTLS and its downgrade and injection cases, AUTH PLAIN and LOGIN, IMAP literals, POP3 deletion on sign-out) are tested against scripted servers in tests/mail_proto.rs, and the sensors' own judgement against scripted clients in tests/sensors_mail_ftp.rs, without a network.

AGPL-3.0-only