Module melib::smtp

source ·
Expand description

SMTP client support

This module implements a client for the SMTP protocol as specified by RFC 5321 Simple Mail Transfer Protocol.

The connection and methods are async and uses the smol runtime.

§Example

extern crate melib;

use melib::futures;
use melib::smol;
use melib::smtp::*;
use melib::Result;
let conf = SmtpServerConf {
    hostname: "smtp.example.com".into(),
    port: 587,
    security: SmtpSecurity::StartTLS {
        danger_accept_invalid_certs: false,
    },
    extensions: SmtpExtensionSupport::default(),
    auth: SmtpAuth::Auto {
        username: "l15".into(),
        password: Password::CommandEval(
            "gpg2 --no-tty -q -d ~/.passwords/mail.gpg".into(),
        ),
        require_auth: true,
    },
};

std::thread::Builder::new().spawn(move || {
    let ex = smol::Executor::new();
    futures::executor::block_on(ex.run(futures::future::pending::<()>()));
}).unwrap();

let mut conn = futures::executor::block_on(SmtpConnection::new_connection(conf)).unwrap();
futures::executor::block_on(conn.mail_transaction(r#"To: l10@example.com
Subject: Fwd: SMTP TEST
From: Me <l15@example.com>
Message-Id: <E1hSjnr-0003fN-RL@example.com>
Date: Mon, 13 Jul 2020 09:02:15 +0300

Prescriptions-R-X"#,
    Some(&[
        Address::try_from("foo-chat@example.com").unwrap(),
    ]),
)).unwrap();
futures::executor::block_on(conn.quit()).unwrap();
Ok(())

Structs§

Enums§

  • Source of user’s password for SMTP authentication
  • Recognized kinds of SMTP reply codes
  • Kind of server authentication the client should attempt
  • Kind of server security (StartTLS/TLS/None) the client should attempt

Type Aliases§