Module std::net::smtp

SMTP client for sending email.

Provides functions for connecting to an SMTP server and sending plain-text or HTML email messages.

Examples

import std::net::smtp;

fn main() {
    smtp.send(
        "smtp.example.com",
        587,
        "user",
        "pass",
        "from@example.com",
        "to@example.com",
        "Subject",
        "Body",
    );
}

Contents

Functions

Function connect

pub fn connect(host: string, port: i64, username: string, password: string) -> Conn

Connect to an SMTP server using STARTTLS.

Examples

let conn = smtp.connect("smtp.example.com", 587, "user", "pass");

Function connect_tls

pub fn connect_tls(host: string, port: i64, username: string, password: string) -> Conn

Connect to an SMTP server using implicit TLS.

Examples

let conn = smtp.connect_tls("smtp.example.com", 465, "user", "pass");

Function send

pub fn send(host: string, port: i64, username: string, password: string, from: string, to: string, subject: string, body: string) -> i64

Connect with the same STARTTLS path as connect(...), send one plain-text email, and close the connection.

Use connect_tls(...) + Conn.send(...) when you need implicit TLS or want to reuse a connection for multiple messages.

Function try_send

pub fn try_send(host: string, port: i64, username: string, password: string, from: string, to: string, subject: string, body: string) -> Result<(), string>

Connect with the same STARTTLS path as connect(...), send one plain-text email, and close the connection.

Function send_html

pub fn send_html(host: string, port: i64, username: string, password: string, from: string, to: string, subject: string, html: string) -> i64

Connect with the same STARTTLS path as connect(...), send one HTML email, and close the connection.

Use connect_tls(...) + Conn.send_html(...) when you need implicit TLS or want to reuse a connection for multiple messages.

Function try_send_html

pub fn try_send_html(host: string, port: i64, username: string, password: string, from: string, to: string, subject: string, html: string) -> Result<(), string>

Connect with the same STARTTLS path as connect(...), send one HTML email, and close the connection.

Types

Struct Conn

An open SMTP connection handle.

Created by calling smtp.connect(...) or smtp.connect_tls(...). Use send() or send_html() to deliver messages.

Traits

Trait ConnMethods

Methods available on an SMTP Conn.

Methods

fn send(self: Self, from: string, to: string, subject: string, body: string) -> i64

Send a plain-text email. Return 0 on success.

fn try_send(self: Self, from: string, to: string, subject: string, body: string) -> Result<(), string>

Send a plain-text email.

fn send_html(self: Self, from: string, to: string, subject: string, html: string) -> i64

Send an HTML email. Return 0 on success.

fn try_send_html(self: Self, from: string, to: string, subject: string, html: string) -> Result<(), string>

Send an HTML email.

fn close(self: Self)

Close the SMTP connection.