Stages
If the concept of stages for filtering is unknown to you, please refer to the Filtering chapter for more details.
The SMTP Receiver services exposes multiple stages that you can hook filtering scripts onto.
Connect
The connect
stage is triggered once a client connects to the SMTP Receiver.
To execute scripts on this stage, wrap your code in a on_connect
function.
fn on_connect(ctx) {
log("info", "A client just connected");
status::next();
}
Helo
The helo
stage is triggered once a client sends the HELO
or EHLO
command to the SMTP Receiver.
To execute scripts on this stage, wrap your code in a on_helo
function.
fn on_helo(ctx) {
log("info", `server indentifier: ${ctx.helo}`);
status::next();
}
Auth
The auth
stage is triggered when the client request authentication to the SMTP Receiver.
To execute scripts on this stage, wrap your code in a on_auth
function.
fn on_auth(ctx) {
log("info", `Authentication id: ${ctx.sasl.authid}`);
status::next();
}
Mail From
The mail from
stage is triggered once a client sends the MAIL FROM:
command to the SMTP Receiver.
To execute scripts on this stage, wrap your code in a on_mail_from
function.
fn on_mail_from(ctx) {
log("info", `Sender address received: ${ctx.sender}`);
status::next();
}
Rcpt To
The rcpt to
stage is triggered every time a client sends the RCPT TO:
command to the SMTP Receiver.
To execute scripts on this stage, wrap your code in a on_rcpt_to
function.
fn on_rcpt_to(ctx) {
log("info", `Updated recipient list: ${ctx.recipients}`);
status::next();
}
Pre-queue
The pre-queue
stage is triggered when the client finished sending the email after a DATA
command to the SMTP Receiver.
To execute scripts on this stage, wrap your code in a on_pre_queue
function.
fn on_pre_queue(ctx) {
log("info", `Email received: ${ctx.mail}`);
status::next();
}
After this stage, the email is sent to the Working service.