pub struct SmtpClient<S> { /* private fields */ }Expand description
One SMTP session.
Implementations§
Source§impl<S: AsyncRead + AsyncWrite + Unpin> SmtpClient<S>
impl<S: AsyncRead + AsyncWrite + Unpin> SmtpClient<S>
Sourcepub async fn open(
stream: S,
server: impl Into<String>,
timeout: Duration,
) -> Result<Self>
pub async fn open( stream: S, server: impl Into<String>, timeout: Duration, ) -> Result<Self>
Take over an open stream and read the server’s greeting.
Sourcepub async fn ehlo(&mut self, name: &str) -> Result<()>
pub async fn ehlo(&mut self, name: &str) -> Result<()>
Say hello and learn what the server supports.
Falls back to HELO when EHLO is refused: a server old enough to
reject it has no capabilities to report anyway.
Sourcepub fn capabilities(&self) -> &[String]
pub fn capabilities(&self) -> &[String]
Every capability line, as the server sent them.
Sourcepub fn supports(&self, capability: &str) -> bool
pub fn supports(&self, capability: &str) -> bool
Whether a capability such as STARTTLS or 8BITMIME was advertised.
Sourcepub fn auth_mechanisms(&self) -> Vec<String>
pub fn auth_mechanisms(&self) -> Vec<String>
The mechanisms listed on the AUTH capability line.
Sourcepub async fn authenticate(
&mut self,
username: &str,
password: &str,
) -> Result<()>
pub async fn authenticate( &mut self, username: &str, password: &str, ) -> Result<()>
Authenticate, preferring AUTH PLAIN and falling back to AUTH LOGIN.
Both send the password base64-encoded, which is not encryption — the caller is responsible for having a TLS connection first.
Sourcepub async fn send_message(
&mut self,
from: &str,
recipients: &[String],
data: &str,
) -> Result<()>
pub async fn send_message( &mut self, from: &str, recipients: &[String], data: &str, ) -> Result<()>
Send one message: envelope, then data.
Every recipient is offered separately, and a rejection names the address the server refused — “send failed” tells nobody anything at 2am.
Sourcepub async fn quit(self)
pub async fn quit(self)
Say goodbye and close. A failure here is not worth reporting: the message was already accepted.
Sourcepub async fn command(&mut self, line: &str) -> Result<Reply>
pub async fn command(&mut self, line: &str) -> Result<Reply>
Send one command and read its reply.
Sourcepub async fn read_reply(&mut self) -> Result<Reply>
pub async fn read_reply(&mut self) -> Result<Reply>
Read exactly one complete reply, however many lines it takes.
Source§impl SmtpClient<SmtpStream>
impl SmtpClient<SmtpStream>
Sourcepub async fn connect(config: &SmtpConfig) -> Result<SmtpClient<SmtpStream>>
pub async fn connect(config: &SmtpConfig) -> Result<SmtpClient<SmtpStream>>
Connect, greet, upgrade to TLS, and authenticate — everything up to the point where a message can be sent.
Sourcepub async fn start_tls(
self,
host: &str,
hello: &str,
) -> Result<SmtpClient<SmtpStream>>
pub async fn start_tls( self, host: &str, hello: &str, ) -> Result<SmtpClient<SmtpStream>>
Upgrade the connection in place, then greet again over TLS.
Consumes the client because the stream changes type. Everything the
server said before the handshake is discarded: capabilities learned in
cleartext are not trustworthy, which is exactly the STARTTLS stripping
attack this re-EHLO defends against.