JFLib

netio/smtp.rs#

Source: lib/netio/smtp.rs

smtp -- sending mail (RFC 5321) for notifications

  send(&SmtpConfig, &Mail) -> Result<String, String>   the server's final answer or the
                                                       reason it failed (German, for people)
  Security::StartTls (port 587) / Tls (465) / None (25; plain to any server, e.g. a relay
  inside a network, and refuses to authenticate in clear: with a user name it is an error)
  AUTH PLAIN or LOGIN (whatever the server offers; PLAIN first)
  message(&Mail, host, now) -> the RFC 5322 text: UTF-8 subject as an encoded word, the body
  text/plain (and text/html as multipart/alternative) in base64, Date and Message-ID

TLS checks the server like a browser (the system's certificate authorities, plus extra CAs
for a company's own); after STARTTLS nothing the server sent before the switch is used
(no command injection across the switch).
  • enum Security
    • StartTls
    • Tls
    • None

impl Security

  • fn parse(s: &str) -> Security

  • fn default_port(self) -> u16

  • struct SmtpConfig

    • host: String
    • port: u16
    • security: Security
    • username: String
    • password: String
    • helo: String -- our name in EHLO
    • extra_cas: Vec<Cert> -- CAs trusted in addition to the system's
    • timeout_ms: u32
  • struct Mail

    • from: String
    • to: Vec<String>
    • subject: String
    • text: String
    • html: String -- an HTML alternative (optional)
  • fn send(cfg: &SmtpConfig, mail: &Mail) -> Result<String, String> send one message

  • fn rfc5322_date(t: i64) -> String "Tue, 13 Oct 2026 15:04:05 +0000"

  • fn message(mail: &Mail, host: &str, now: i64) -> String the message text (CRLF line ends)

Source: docs/API.md in the JFLib repository.