#email #smtp #mailer


UNMAINTAINED - Replaced by the ‘lettre’ crate

20 releases

Uses old Rust 2015

0.3.2 Aug 26, 2021
0.3.0 Oct 12, 2015
0.1.1 Jul 22, 2015
0.0.9 Mar 20, 2015
0.0.2 Nov 21, 2014

#97 in Email

Download history 22/week @ 2021-10-03 20/week @ 2021-10-10 4/week @ 2021-10-17 4/week @ 2021-10-24 19/week @ 2021-10-31 26/week @ 2021-11-07 12/week @ 2021-11-14 15/week @ 2021-11-21 27/week @ 2021-11-28 8/week @ 2021-12-05 12/week @ 2021-12-12 10/week @ 2021-12-19 17/week @ 2021-12-26 39/week @ 2022-01-02 11/week @ 2022-01-09

79 downloads per month

MIT license

1.5K SLoC

rust-smtp Build Status Coverage Status Crate MIT licensed

WARNING: This library is no longer maintained and is replaced by the lettre crate.


To use this library, add the following to your Cargo.toml:

smtp = "0.3"


This program is distributed under the terms of the MIT license.

See LICENSE for details.


Rust SMTP client

This client should tend to follow RFC 5321, but is still a work in progress. It is designed to efficiently send emails from an application to a relay email server, as it relies as much as possible on the relay server for sanity and RFC compliance checks.

It implements the following extensions:

It will eventually implement the following extensions:


This client is divided into three main parts:

  • client: a low level SMTP client providing all SMTP commands
  • sender: a high level SMTP client providing an easy method to send emails
  • email: generates the email to be sent with the sender


Simple example

This is the most basic example of usage:

use smtp::sender::{Sender, SenderBuilder};
use smtp::email::EmailBuilder;

// Create an email
let email = EmailBuilder::new()
    // Addresses can be specified by the couple (email, alias)
    .to(("user@example.org", "Firstname Lastname"))
    // ... or by an address only
    .subject("Hi, Hello world")
    .body("Hello world.")

// Open a local connection on port 25
let mut sender = SenderBuilder::localhost().unwrap().build();
// Send the email
let result = sender.send(email);


Complete example

use smtp::sender::{Sender, SenderBuilder};
use smtp::email::EmailBuilder;
use smtp::authentication::Mecanism;

let mut builder = EmailBuilder::new();
builder = builder.to(("user@example.org", "Alias name"));
builder = builder.cc(("user@example.net", "Alias name"));
builder = builder.from("no-reply@example.com");
builder = builder.from("no-reply@example.eu");
builder = builder.sender("no-reply@example.com");
builder = builder.subject("Hello world");
builder = builder.body("Hi, Hello world.");
builder = builder.reply_to("contact@example.com");
builder = builder.add_header(("X-Custom-Header", "my header"));

let email = builder.build();

// Connect to a remote server on a custom port
let mut sender = SenderBuilder::new(("server.tld", SUBMISSION_PORT)).unwrap()
    // Set the name sent during EHLO/HELO, default is `localhost`
    // Add credentials for authentication
    .credentials("username", "password")
    // Use TLS with STARTTLS, you can also specify a specific SSL context
    // with `.ssl_context(context)`
    // Configure accepted authetication mecanisms
    // Enable connection reuse

let result_1 = sender.send(email.clone());

// The second email will use the same connection
let result_2 = sender.send(email);

// Explicitely close the SMTP transaction as we enabled connection reuse

Using the client directly

If you just want to send an email without using Email to provide headers:

use smtp::sender::{Sender, SenderBuilder};
use smtp::email::SimpleSendableEmail;

// Create a minimal email
let email = SimpleSendableEmail::new(
    "Hello world !"

let mut sender = SenderBuilder::localhost().unwrap().build();
let result = sender.send(email);

Lower level

You can also send commands, here is a simple email transaction without error handling:

use smtp::client::Client;
use smtp::SMTP_PORT;
use smtp::client::net::NetworkStream;

let mut email_client: Client<NetworkStream> = Client::new();
let _ = email_client.connect(&("localhost", SMTP_PORT));
let _ = email_client.ehlo("my_hostname");
let _ = email_client.mail("user@example.com", None);
let _ = email_client.rcpt("user@example.org");
let _ = email_client.data();
let _ = email_client.message("Test email");
let _ = email_client.quit();


~152K SLoC