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>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 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>
Drives 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<Greeting<'static>, SmtpClientStdError>
pub fn greeting(&mut self) -> Result<Greeting<'static>, SmtpClientStdError>
Runs SmtpGreetingGet: reads the initial server greeting. Call this
once after new / connect.
Sourcepub fn ehlo(
&mut self,
domain: EhloDomain<'_>,
) -> Result<Vec<Cow<'static, str>>, SmtpClientStdError>
pub fn ehlo( &mut self, domain: EhloDomain<'_>, ) -> 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 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: EhloDomain<'_>,
) -> Result<(), SmtpClientStdError>
pub fn auth_anonymous( &mut self, trace: Option<&str>, domain: EhloDomain<'_>, ) -> Result<(), SmtpClientStdError>
Runs [SmtpAnonymous] (AUTH ANONYMOUS, RFC 4505). Refreshes the
capability list with an EHLO after a successful authentication. 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: EhloDomain<'_>,
) -> Result<(), SmtpClientStdError>
pub fn auth_login( &mut self, login: &str, password: &SecretString, domain: EhloDomain<'_>, ) -> Result<(), SmtpClientStdError>
Runs SmtpAuthLogin (AUTH LOGIN, legacy SASL mechanism). Refreshes
the capability list with an EHLO after a successful
authentication. Prefer auth_plain or auth_scram_sha256 when the
server supports them.
Sourcepub fn auth_plain(
&mut self,
login: &str,
password: &SecretString,
domain: EhloDomain<'_>,
) -> Result<(), SmtpClientStdError>
pub fn auth_plain( &mut self, login: &str, password: &SecretString, domain: EhloDomain<'_>, ) -> Result<(), SmtpClientStdError>
Runs SmtpAuthPlain (AUTH PLAIN, RFC 4616). Refreshes the
capability list with an EHLO after a successful authentication.
Sourcepub fn auth_oauthbearer(
&mut self,
token: &SecretString,
username: Option<&str>,
domain: EhloDomain<'_>,
) -> Result<(), SmtpClientStdError>
pub fn auth_oauthbearer( &mut self, token: &SecretString, username: Option<&str>, domain: EhloDomain<'_>, ) -> Result<(), SmtpClientStdError>
Runs SmtpAuthOauthbearer (AUTH OAUTHBEARER, RFC 7628). Refreshes
the capability list with an EHLO after a successful
authentication. 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: EhloDomain<'_>,
) -> Result<(), SmtpClientStdError>
pub fn auth_xoauth2( &mut self, username: &str, token: &SecretString, domain: EhloDomain<'_>, ) -> Result<(), SmtpClientStdError>
Runs SmtpAuthXoauth2 (AUTH XOAUTH2, Google’s pre-standard OAuth
2.0 SASL mechanism). Refreshes the capability list with an EHLO after
a successful authentication. 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: EhloDomain<'_>,
) -> Result<(), SmtpClientStdError>
Available on crate feature scram only.
pub fn auth_scram_sha256( &mut self, username: &str, password: &SecretString, nonce: &[u8], domain: EhloDomain<'_>, ) -> Result<(), SmtpClientStdError>
scram only.Runs SmtpAuthScramSha256 (AUTH SCRAM-SHA-256, RFC 7677).
Refreshes the capability list with an EHLO after a successful
authentication. nonce must be printable ASCII (no commas); the
standard recommends at least 18 bytes of cryptographic randomness.
Sourcepub fn mail(
&mut self,
reverse_path: ReversePath<'_>,
parameters: Vec<Parameter<'_>>,
) -> Result<(), SmtpClientStdError>
pub fn mail( &mut self, reverse_path: ReversePath<'_>, parameters: Vec<Parameter<'_>>, ) -> 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: ForwardPath<'_>,
parameters: Vec<Parameter<'_>>,
) -> Result<(), SmtpClientStdError>
pub fn rcpt( &mut self, forward_path: ForwardPath<'_>, parameters: Vec<Parameter<'_>>, ) -> 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 send<'a>(
&mut self,
reverse_path: ReversePath<'_>,
forward_paths: impl IntoIterator<Item = ForwardPath<'a>>,
message: Vec<u8>,
) -> Result<(), SmtpClientStdError>
pub fn send<'a>( &mut self, reverse_path: ReversePath<'_>, forward_paths: impl IntoIterator<Item = ForwardPath<'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: EhloDomain<'_>,
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: EhloDomain<'_>, 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 (seedefault_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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
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.