Skip to content

Commit

Permalink
add error explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoCasa committed Oct 2, 2024
1 parent bd1e77a commit 56df705
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions blog/2024-10-07-email-triggers/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ async fn handle_connection(stream: &mut TcpStream) {

## Implementing the SMTP exchange loop

Once the sender (server or client) connects, it starts sending commands.
You can find the full list of possible commands [here](https://datatracker.ietf.org/doc/html/rfc5321#section-4).
Once the sender (server or client) connects, it begins sending commands.
You can find the full list of possible commands in [RFC 5321](https://datatracker.ietf.org/doc/html/rfc5321#section-4).

A simplified flow of commands could be:
- Sender: EHLO
Expand Down Expand Up @@ -121,6 +121,11 @@ We have three states:
We use `Framed` with `LinesCodec` from the [tokio-util](https://crates.io/crates/tokio-util) crate to split the stream by lines.
We use regular expressions to parse the sender and receiver addresses.

For each command, we check if it is valid and respond accordingly.
If the command is valid, we send a response to the client with the appropriate code from [RFC 5321](https://datatracker.ietf.org/doc/html/rfc5321#section-4.2.2).
The message following the code is customizable.
If the command results in an error, such as an invalid command or attempting to send an email before specifying the recipient, we send the corresponding error code and message to the client.

```rust
use tokio_util::codec::{Framed, LinesCodec, LinesCodecError};
use futures::{stream::iter, SinkExt, StreamExt};
Expand Down Expand Up @@ -233,7 +238,7 @@ async fn send_commands(

## STARTTLS

As explained above, to secure the communication between SMTP servers, we should use [STARTTLS](https://www.ietf.org/rfc/rfc3207.txt).
As explained above, to secure the communication between SMTP servers, we should use STARTTLS ([RFC 3207](https://www.ietf.org/rfc/rfc3207.txt)).
This protocol allows an existing insecure connection to be upgraded to a TLS connection.

The flow begins the same way as before but the server specifies that it supports TLS by sending the `250-STARTTLS` response to the `EHLO` command.
Expand Down

0 comments on commit 56df705

Please sign in to comment.