std::net::smtpSMTP client for sending email.
Provides functions for connecting to an SMTP server and sending plain-text or HTML email messages.
import std.net.smtp;
fn main() {
let _ = smtp.send(
"smtp.example.com",
587,
"user",
"pass",
"from@example.com",
"to@example.com",
"Subject",
"Body",
).expect("the call succeeds");
}
last_errorReturn the last SMTP client error observed on this thread.
Failed connect()/connect_tls()/send() calls update this string.
Successful sends clear it. Call immediately after a failed
connect/send for the precise reason.
connectConnect to an SMTP server using STARTTLS.
The connection is opened and probed before it is returned, so an unreachable host, a refused port, or a server that is not speaking SMTP is reported here rather than at the first send.
import std.net.smtp;
fn main() {
match smtp.connect("smtp.example.com", 587, "user", "pass") {
.Ok(conn) => conn.close(),
.Err(reason) => println(f"connect failed: {reason}"),
}
}
connect_tlsConnect to an SMTP server using implicit TLS.
The connection is opened and probed before it is returned, so an unreachable host, a refused port, or a server that is not speaking SMTP is reported here rather than at the first send.
import std.net.smtp;
fn main() {
match smtp.connect_tls("smtp.example.com", 465, "user", "pass") {
.Ok(conn) => conn.close(),
.Err(reason) => println(f"connect failed: {reason}"),
}
}
sendConnect with the same STARTTLS path as connect(...), send one plain-text
email, and close the connection.
send_htmlConnect with the same STARTTLS path as connect(...), send one HTML email,
and close the connection.
ConnAn open SMTP connection handle.
Created by calling smtp.connect(...) or smtp.connect_tls(...), which
probe the server before returning Ok and report an unreachable or
non-SMTP endpoint as Err.
Use send() or send_html() to deliver messages.
ConnMethodsMethods available on an SMTP Conn.
Send a plain-text email.
Send an HTML email.