<a id="smtp-server"></a>

# SMTP server

There are multiple extensions to the language, which provides context specific variables and functions. The *smtpd* process implements the [connect](connect.html.md), [proxy](proxy.html.md), [HELO](helo.html.md), [AUTH](auth.html.md), [MAIL FROM](mailfrom.html.md), [RCPT TO](rcptto.html.md), [end-of-DATA](eod.html.md) and [disconnect](disconnect.html.md) context. These scripts operates on an SMTP connection. The `$transaction["id"]` variable is set when connecting and may be regenerated upon the client sending a RSET command. There is also a `$context` variable which is bound to a connection and may be used in any script, which is useful for passing data (only string, number, boolean, null and array types are supported) between phases.

```default
  .--------------------------------. <-- connect context
< | 220 example.org ESMTP          |
> | HELO example.com               | <-- HELO context
< | 250 OK                         |
  | ...                            |
> | AUTH LOGIN                     | <-- AUTH context
  | ...                            |
< | 250 OK                         |
> | MAIL FROM: <john@example.org>  | <-- MAIL FROM context
< | 250 OK                         |
> | RCPT TO: <jane@example.com>    | <-- RCPT TO context
< | 250 OK                         |
> | DATA                           |
< | 354 Feed me                    |
> | Subject: Lunch                 |
> |                                |
> | Lunch on friday?               |
> | .                              | <-- end-of-DATA context
< | 250 Accepted                   |
> | QUIT                           |
< | 250 Bye                        |
  `--------------------------------´ <-- disconnect context
               |
   ,-------> queue
   |           |                     <-- Pre-delivery context
   |   delivery attempt
   |           |                     <-- Post-delivery context
   \__________/ \______ done
```

* [Connect](connect.html.md)
  * [Variables](connect.html.md#variables)
    * [Arguments](connect.html.md#arguments)
    * [Connection](connect.html.md#connection)
    * [Transaction](connect.html.md#transaction)
  * [Functions](connect.html.md#functions)
    * [`Accept()`](connect.html.md#Accept)
    * [`Reject()`](connect.html.md#Reject)
    * [`Defer()`](connect.html.md#Defer)
  * [On script error](connect.html.md#on-script-error)
  * [On implicit termination](connect.html.md#on-implicit-termination)
* [Proxy](proxy.html.md)
  * [Variables](proxy.html.md#variables)
    * [Arguments](proxy.html.md#arguments)
    * [Connection](proxy.html.md#connection)
      * [HELO](proxy.html.md#helo)
      * [TLS](proxy.html.md#tls)
        * [Peercert](proxy.html.md#peercert)
      * [AUTH](proxy.html.md#auth)
    * [Transaction](proxy.html.md#transaction)
      * [Recipient](proxy.html.md#recipient)
      * [Address](proxy.html.md#address)
  * [Functions](proxy.html.md#functions)
    * [`Pass()`](proxy.html.md#Pass)
    * [`Reply()`](proxy.html.md#Reply)
    * [`Next()`](proxy.html.md#Next)
  * [On script error](proxy.html.md#on-script-error)
  * [On implicit termination](proxy.html.md#on-implicit-termination)
* [HELO](helo.html.md)
  * [Variables](helo.html.md#variables)
    * [Arguments](helo.html.md#arguments)
    * [Connection](helo.html.md#connection)
      * [TLS](helo.html.md#tls)
        * [Peercert](helo.html.md#peercert)
      * [AUTH](helo.html.md#auth)
    * [Transaction](helo.html.md#transaction)
  * [Functions](helo.html.md#functions)
    * [`Accept()`](helo.html.md#Accept)
    * [`Reject()`](helo.html.md#Reject)
    * [`Defer()`](helo.html.md#Defer)
  * [On script error](helo.html.md#on-script-error)
  * [On implicit termination](helo.html.md#on-implicit-termination)
* [AUTH](auth.html.md)
  * [Variables](auth.html.md#variables)
    * [Arguments](auth.html.md#arguments)
    * [Connection](auth.html.md#connection)
      * [HELO](auth.html.md#helo)
      * [TLS](auth.html.md#tls)
        * [Peercert](auth.html.md#peercert)
    * [Transaction](auth.html.md#transaction)
  * [Functions](auth.html.md#functions)
    * [`Accept()`](auth.html.md#Accept)
    * [`Reject()`](auth.html.md#Reject)
    * [`Defer()`](auth.html.md#Defer)
    * [`Reply()`](auth.html.md#Reply)
  * [On script error](auth.html.md#on-script-error)
  * [On implicit termination](auth.html.md#on-implicit-termination)
  * [Authentication diagram](auth.html.md#authentication-diagram)
* [MAIL FROM](mailfrom.html.md)
  * [Variables](mailfrom.html.md#variables)
    * [Arguments](mailfrom.html.md#arguments)
    * [Connection](mailfrom.html.md#connection)
      * [HELO](mailfrom.html.md#helo)
      * [TLS](mailfrom.html.md#tls)
        * [Peercert](mailfrom.html.md#peercert)
      * [AUTH](mailfrom.html.md#auth)
    * [Transaction](mailfrom.html.md#transaction)
      * [Address](mailfrom.html.md#address)
  * [Functions](mailfrom.html.md#functions)
    * [`Accept()`](mailfrom.html.md#Accept)
    * [`Reject()`](mailfrom.html.md#Reject)
    * [`Defer()`](mailfrom.html.md#Defer)
  * [On script error](mailfrom.html.md#on-script-error)
  * [On implicit termination](mailfrom.html.md#on-implicit-termination)
* [RCPT TO](rcptto.html.md)
  * [Variables](rcptto.html.md#variables)
    * [Arguments](rcptto.html.md#arguments)
    * [Connection](rcptto.html.md#connection)
      * [HELO](rcptto.html.md#helo)
      * [TLS](rcptto.html.md#tls)
        * [Peercert](rcptto.html.md#peercert)
      * [AUTH](rcptto.html.md#auth)
    * [Transaction](rcptto.html.md#transaction)
      * [Recipient](rcptto.html.md#recipient)
      * [Address](rcptto.html.md#address)
  * [Functions](rcptto.html.md#functions)
    * [`Accept()`](rcptto.html.md#Accept)
    * [`Reject()`](rcptto.html.md#Reject)
    * [`Defer()`](rcptto.html.md#Defer)
  * [On script error](rcptto.html.md#on-script-error)
  * [On implicit termination](rcptto.html.md#on-implicit-termination)
* [End-of-DATA](eod.html.md)
  * [Variables](eod.html.md#variables)
    * [Arguments](eod.html.md#arguments)
    * [Connection](eod.html.md#connection)
      * [HELO](eod.html.md#helo)
      * [TLS](eod.html.md#tls)
        * [Peercert](eod.html.md#peercert)
      * [AUTH](eod.html.md#auth)
    * [Transaction](eod.html.md#transaction)
      * [Recipient](eod.html.md#recipient)
      * [Address](eod.html.md#address)
      * [http](eod.html.md#http)
  * [Functions](eod.html.md#functions)
    * [Actions](eod.html.md#actions)
      * [`Accept()`](eod.html.md#Accept)
      * [`Reject()`](eod.html.md#Reject)
      * [`Defer()`](eod.html.md#Defer)
    * [DATA, MIME and attachments](eod.html.md#data-mime-and-attachments)
      * [`EODMailMessage`](eod.html.md#_CPPv414EODMailMessage)
      * [`EODMailMessage.queue()`](eod.html.md#EODMailMessage.queue)
  * [On script error](eod.html.md#on-script-error)
  * [On implicit termination](eod.html.md#on-implicit-termination)
* [Disconnect](disconnect.html.md)
  * [Variables](disconnect.html.md#variables)
    * [Arguments](disconnect.html.md#arguments)
      * [Error](disconnect.html.md#error)
      * [Reply](disconnect.html.md#reply)
    * [Connection](disconnect.html.md#connection)
      * [HELO](disconnect.html.md#helo)
      * [TLS](disconnect.html.md#tls)
        * [Peercert](disconnect.html.md#peercert)
      * [AUTH](disconnect.html.md#auth)
  * [Functions](disconnect.html.md#functions)
    * [`Pass()`](disconnect.html.md#Pass)
  * [On script error](disconnect.html.md#on-script-error)
  * [On implicit termination](disconnect.html.md#on-implicit-termination)
