pub struct SmtpClientStd {
pub stream: Box<dyn SmtpStream>,
}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
impl SmtpClientStd
Sourcepub fn new<S: Read + Write + Send + 'static>(stream: S) -> Self
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).
Sourcepub fn default_alpn() -> Vec<String>
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.
Sourcepub fn default_port(scheme: &str) -> u16
pub fn default_port(scheme: &str) -> u16
Default SMTP port for scheme: 465 for smtps, 25 otherwise.
Sourcepub fn set_stream<S: Read + Write + Send + 'static>(&mut self, stream: S)
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.
Sourcepub fn run<C, T, E>(&mut self, coroutine: C) -> Result<T, SmtpClientStdError>
pub fn run<C, T, E>(&mut self, coroutine: C) -> Result<T, SmtpClientStdError>
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.
Sourcepub fn greeting(&mut self) -> Result<SmtpGreeting<'static>, SmtpClientStdError>
pub fn greeting(&mut self) -> Result<SmtpGreeting<'static>, SmtpClientStdError>
Runs SmtpGreetingGet: reads the initial server greeting. Call this
once after new / connect.
Sourcepub fn ehlo(
&mut self,
domain: SmtpEhloDomain<'_>,
) -> Result<Vec<Cow<'static, str>>, SmtpClientStdError>
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.
Sourcepub fn helo(&mut self, domain: SmtpDomain<'_>) -> Result<(), SmtpClientStdError>
pub fn helo(&mut self, domain: SmtpDomain<'_>) -> Result<(), SmtpClientStdError>
Sourcepub fn starttls(&mut self) -> Result<Vec<u8>, SmtpClientStdError>
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).
Sourcepub fn quit(&mut self) -> Result<(), SmtpClientStdError>
pub fn quit(&mut self) -> Result<(), SmtpClientStdError>
Runs SmtpQuit (QUIT, RFC 5321 §4.1.1.10).
Sourcepub fn auth_anonymous(
&mut self,
trace: Option<&str>,
domain: SmtpEhloDomain<'_>,
) -> Result<(), SmtpClientStdError>
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.
Sourcepub fn auth_login(
&mut self,
login: &str,
password: &SecretString,
domain: SmtpEhloDomain<'_>,
) -> Result<(), SmtpClientStdError>
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.
Sourcepub fn auth_plain(
&mut self,
login: &str,
password: &SecretString,
domain: SmtpEhloDomain<'_>,
) -> Result<(), SmtpClientStdError>
pub fn auth_plain( &mut self, login: &str, password: &SecretString, domain: SmtpEhloDomain<'_>, ) -> Result<(), SmtpClientStdError>
Runs SmtpAuthPlain (AUTH PLAIN, RFC 4616).
Sourcepub fn auth_oauthbearer(
&mut self,
token: &SecretString,
username: Option<&str>,
domain: SmtpEhloDomain<'_>,
) -> Result<(), SmtpClientStdError>
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.
Sourcepub fn auth_xoauth2(
&mut self,
username: &str,
token: &SecretString,
domain: SmtpEhloDomain<'_>,
) -> Result<(), SmtpClientStdError>
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.
Sourcepub fn auth_scram_sha256(
&mut self,
username: &str,
password: &SecretString,
nonce: &[u8],
domain: SmtpEhloDomain<'_>,
) -> Result<(), SmtpClientStdError>
Available on crate feature scram only.
pub fn auth_scram_sha256( &mut self, username: &str, password: &SecretString, nonce: &[u8], domain: SmtpEhloDomain<'_>, ) -> Result<(), SmtpClientStdError>
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.
Sourcepub fn mail(
&mut self,
reverse_path: SmtpReversePath<'_>,
parameters: Vec<SmtpParameter<'_>>,
) -> Result<(), SmtpClientStdError>
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).
Sourcepub fn rcpt(
&mut self,
forward_path: SmtpForwardPath<'_>,
parameters: Vec<SmtpParameter<'_>>,
) -> Result<(), SmtpClientStdError>
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=).
Sourcepub fn data(&mut self, message: Vec<u8>) -> Result<(), SmtpClientStdError>
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.
Sourcepub fn rset(&mut self) -> Result<(), SmtpClientStdError>
pub fn rset(&mut self) -> Result<(), SmtpClientStdError>
Runs SmtpRset (RSET, RFC 5321 §4.1.1.5). Aborts the
current mail transaction.
Sourcepub fn noop(&mut self) -> Result<(), SmtpClientStdError>
pub fn noop(&mut self) -> Result<(), SmtpClientStdError>
Runs SmtpNoop (NOOP, RFC 5321 §4.1.1.9).
Sourcepub fn raw(
&mut self,
command: impl Into<Cow<'static, str>>,
) -> Result<String, SmtpClientStdError>
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.
Sourcepub fn send<'a>(
&mut self,
reverse_path: SmtpReversePath<'_>,
forward_paths: impl IntoIterator<Item = SmtpForwardPath<'a>>,
message: Vec<u8>,
) -> Result<(), SmtpClientStdError>
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
impl SmtpClientStd
Sourcepub 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.
pub fn connect( url: &Url, tls: &Tls, starttls: bool, domain: SmtpEhloDomain<'_>, sasl: Option<impl Into<Sasl>>, ) -> Result<Self, SmtpClientStdError>
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).tlscarries the rustls/native-tls knobs and the ALPN list (seeSelf::default_alpnfor the SMTP-conformant["smtp"]). Settls.rustls.alpnto an empty vec to skip ALPN.starttls = true(only valid onsmtp://) performs the SMTPSTARTTLSupgrade and runs a fresh EHLO over TLS.domainis the client identifier sent in EHLO (typically the sending host’s name or an address literal).saslis the optional SASL mechanism. Accepts anything that converts into aSasl, so callers can pass the per-mechanism struct directly (e.g.Some(SaslPlain { .. })) without wrapping it in aSaslvariant. Supported mechanisms:SaslAnonymous(RFC 4505),SaslLogin(legacy two-prompt LOGIN),SaslPlain(RFC 4616),SaslOauthbearer(RFC 7628),SaslXoauth2(Google), andSaslScramSha256(RFC 7677, behind thescramcargo feature). PassNoneto skip authentication.
Returns a fully authenticated client ready to issue further commands.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for SmtpClientStd
impl !Sync for SmtpClientStd
impl !UnwindSafe for SmtpClientStd
impl Freeze for SmtpClientStd
impl Send for SmtpClientStd
impl Unpin for SmtpClientStd
impl UnsafeUnpin for SmtpClientStd
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, S> SpanWrap<S> for Twhere
S: WrappingSpan<T>,
impl<T, S> SpanWrap<S> for Twhere
S: WrappingSpan<T>,
Source§fn with_span(self, span: S) -> <S as WrappingSpan<Self>>::Spanned
fn with_span(self, span: S) -> <S as WrappingSpan<Self>>::Spanned
WrappingSpan::make_wrapped to wrap an AST node in a span.