Skip to main content

SmtpClientStd

Struct SmtpClientStd 

Source
pub struct SmtpClientStd {
    pub stream: Box<dyn SmtpStream>,
}
Available on crate feature client only.
Expand description

Std-blocking SMTP client wrapping a single boxed stream.

Fields§

§stream: Box<dyn SmtpStream>

The wrapped stream every coroutine is pumped against.

Implementations§

Source§

impl SmtpClientStd

Source

pub fn new<S: Read + Write + Send + 'static>(stream: S) -> Self

Builds a client around stream. The caller is responsible for opening the connection (TCP, TLS handshake if needed, STARTTLS upgrade if needed).

Source

pub fn default_alpn() -> Vec<String>

Default ALPN protocol identifier offered during the TLS handshake for SMTP submission connections (RFC 7595 registers the smtp token). Exposed so config-based callers can use it as a serde default and so wizard/discovery code shares a single source of truth.

Source

pub fn default_port(scheme: &str) -> u16

Default SMTP port for scheme: 465 for smtps, 25 otherwise.

Source

pub fn set_stream<S: Read + Write + Send + 'static>(&mut self, stream: S)

Replaces the underlying stream; useful after a caller-managed TLS upgrade or reconnection.

Source

pub fn run<C, T, E>(&mut self, coroutine: C) -> Result<T, SmtpClientStdError>
where C: SmtpCoroutine<Yield = SmtpYield, Return = Result<T, E>>, SmtpClientStdError: From<E>,

Pumps any standard-shape coroutine (Yield = SmtpYield, Return = Result<Output, Error>) against the wrapped stream until it terminates. Every coroutine in this crate (including SmtpStartTls) fits this signature.

Source

pub fn greeting(&mut self) -> Result<SmtpGreeting<'static>, SmtpClientStdError>

Runs SmtpGreetingGet: reads the initial server greeting. Call this once after new / connect.

Source

pub fn ehlo( &mut self, domain: SmtpEhloDomain<'_>, ) -> Result<Vec<Cow<'static, str>>, SmtpClientStdError>

Runs SmtpEhlo (EHLO <domain>, RFC 5321 §4.1.1.1). Returns the raw capability lines reported by the server.

Source

pub fn helo(&mut self, domain: SmtpDomain<'_>) -> Result<(), SmtpClientStdError>

Runs SmtpHelo (HELO <domain>, RFC 5321 §4.1.1.1). Use ehlo on any modern server; fall back to HELO only if the server rejects EHLO with 500/502.

Source

pub fn starttls(&mut self) -> Result<Vec<u8>, SmtpClientStdError>

Runs SmtpStartTls (STARTTLS, RFC 3207). On success the caller must upgrade the underlying socket to TLS (via StreamStd::upgrade_tls), then build a new client around the upgraded stream and re-issue ehlo. The returned bytes are anything the coroutine pre-read past the 220 reply (normally empty; any pre-handshake bytes are a classic STARTTLS-injection signal).

Source

pub fn quit(&mut self) -> Result<(), SmtpClientStdError>

Runs SmtpQuit (QUIT, RFC 5321 §4.1.1.10).

Source

pub fn auth_anonymous( &mut self, trace: Option<&str>, domain: SmtpEhloDomain<'_>, ) -> Result<(), SmtpClientStdError>

Runs SmtpAuthAnonymous (AUTH ANONYMOUS, RFC 4505). The optional trace token is sent in cleartext for server-side logging; do not put credentials in it.

Source

pub fn auth_login( &mut self, login: &str, password: &SecretString, domain: SmtpEhloDomain<'_>, ) -> Result<(), SmtpClientStdError>

Runs SmtpAuthLogin (AUTH LOGIN, legacy SASL mechanism). Prefer auth_plain or auth_scram_sha256 when the server supports them.

Source

pub fn auth_plain( &mut self, login: &str, password: &SecretString, domain: SmtpEhloDomain<'_>, ) -> Result<(), SmtpClientStdError>

Runs SmtpAuthPlain (AUTH PLAIN, RFC 4616).

Source

pub fn auth_oauthbearer( &mut self, token: &SecretString, username: Option<&str>, domain: SmtpEhloDomain<'_>, ) -> Result<(), SmtpClientStdError>

Runs SmtpAuthOauthbearer (AUTH OAUTHBEARER, RFC 7628). The token is an OAuth 2.0 bearer access token: the connection must be TLS-protected before calling this method.

Source

pub fn auth_xoauth2( &mut self, username: &str, token: &SecretString, domain: SmtpEhloDomain<'_>, ) -> Result<(), SmtpClientStdError>

Runs SmtpAuthXoauth2 (AUTH XOAUTH2, Google’s pre-standard OAuth 2.0 SASL mechanism). The token is an OAuth 2.0 bearer access token: the connection must be TLS-protected before calling this method. Prefer auth_oauthbearer on servers that support both.

Source

pub fn auth_scram_sha256( &mut self, username: &str, password: &SecretString, nonce: &[u8], domain: SmtpEhloDomain<'_>, ) -> Result<(), SmtpClientStdError>

Available on crate feature scram only.

Runs SmtpAuthScramSha256 (AUTH SCRAM-SHA-256, RFC 7677). nonce must be printable ASCII (no commas); the standard recommends at least 18 bytes of cryptographic randomness.

Source

pub fn mail( &mut self, reverse_path: SmtpReversePath<'_>, parameters: Vec<SmtpParameter<'_>>, ) -> Result<(), SmtpClientStdError>

Runs SmtpMail (MAIL FROM:<reverse-path>, RFC 5321 §4.1.1.2). Pass an empty parameters vector for the bare form, non-empty entries for ESMTP parameters (e.g. SIZE=, BODY=, DSN).

Source

pub fn rcpt( &mut self, forward_path: SmtpForwardPath<'_>, parameters: Vec<SmtpParameter<'_>>, ) -> Result<(), SmtpClientStdError>

Runs SmtpRcpt (RCPT TO:<forward-path>, RFC 5321 §4.1.1.3). Pass an empty parameters vector for the bare form, non-empty entries for ESMTP parameters (e.g. DSN NOTIFY=, ORCPT=).

Source

pub fn data(&mut self, message: Vec<u8>) -> Result<(), SmtpClientStdError>

Runs SmtpData (DATA + body terminator, RFC 5321 §4.1.1.4). The coroutine handles dot-stuffing automatically.

Source

pub fn rset(&mut self) -> Result<(), SmtpClientStdError>

Runs SmtpRset (RSET, RFC 5321 §4.1.1.5). Aborts the current mail transaction.

Source

pub fn noop(&mut self) -> Result<(), SmtpClientStdError>

Runs SmtpNoop (NOOP, RFC 5321 §4.1.1.9).

Source

pub fn raw( &mut self, command: impl Into<Cow<'static, str>>, ) -> Result<String, SmtpClientStdError>

Runs SmtpRaw: sends an arbitrary command line (without the trailing CRLF) and returns the server reply verbatim. Reserved for simple request/reply commands; do not use for DATA or STARTTLS, which switch the stream into a different mode.

Source

pub fn send<'a>( &mut self, reverse_path: SmtpReversePath<'_>, forward_paths: impl IntoIterator<Item = SmtpForwardPath<'a>>, message: Vec<u8>, ) -> Result<(), SmtpClientStdError>

Runs SmtpMessageSend: a complete MAIL FROM / RCPT TO (one per recipient) / DATA exchange in one call.

Source§

impl SmtpClientStd

Source

pub fn connect( url: &Url, tls: &Tls, starttls: bool, domain: SmtpEhloDomain<'_>, sasl: Option<impl Into<Sasl>>, ) -> Result<Self, SmtpClientStdError>

Available on crate features native-tls or rustls-aws or rustls-ring only.

Connects to url, reads the greeting, sends an initial EHLO, optionally performs the STARTTLS upgrade (then re-sends EHLO), and finally runs the chosen SASL mechanism.

  • smtp:// goes through plain TCP (port defaults to 25).
  • smtps:// goes through implicit TLS (port defaults to 465).
  • tls carries the rustls/native-tls knobs and the ALPN list (see Self::default_alpn for the SMTP-conformant ["smtp"]). Set tls.rustls.alpn to an empty vec to skip ALPN.
  • starttls = true (only valid on smtp://) performs the SMTP STARTTLS upgrade and runs a fresh EHLO over TLS.
  • domain is the client identifier sent in EHLO (typically the sending host’s name or an address literal).
  • sasl is the optional SASL mechanism. Accepts anything that converts into a Sasl, so callers can pass the per-mechanism struct directly (e.g. Some(SaslPlain { .. })) without wrapping it in a Sasl variant. Supported mechanisms: SaslAnonymous (RFC 4505), SaslLogin (legacy two-prompt LOGIN), SaslPlain (RFC 4616), SaslOauthbearer (RFC 7628), SaslXoauth2 (Google), and SaslScramSha256 (RFC 7677, behind the scram cargo feature). Pass None to skip authentication.

Returns a fully authenticated client ready to issue further commands.

Trait Implementations§

Source§

impl Debug for SmtpClientStd

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

Source§

type Proj<U: 'src> = U

Source§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, S> SpanWrap<S> for T
where S: WrappingSpan<T>,

Source§

fn with_span(self, span: S) -> <S as WrappingSpan<Self>>::Spanned

Invokes WrappingSpan::make_wrapped to wrap an AST node in a span.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.