Skip to main content

SmtpClient

Struct SmtpClient 

Source
pub struct SmtpClient<S> { /* private fields */ }
Expand description

One SMTP session.

Implementations§

Source§

impl<S: AsyncRead + AsyncWrite + Unpin> SmtpClient<S>

Source

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.

Source

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.

Source

pub fn capabilities(&self) -> &[String]

Every capability line, as the server sent them.

Source

pub fn supports(&self, capability: &str) -> bool

Whether a capability such as STARTTLS or 8BITMIME was advertised.

Source

pub fn auth_mechanisms(&self) -> Vec<String>

The mechanisms listed on the AUTH capability line.

Source

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.

Source

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.

Source

pub async fn quit(self)

Say goodbye and close. A failure here is not worth reporting: the message was already accepted.

Source

pub async fn command(&mut self, line: &str) -> Result<Reply>

Send one command and read its reply.

Source

pub async fn read_reply(&mut self) -> Result<Reply>

Read exactly one complete reply, however many lines it takes.

Source§

impl SmtpClient<SmtpStream>

Source

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.

Source

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.

Source

pub fn is_encrypted(&self) -> bool

Auto Trait Implementations§

§

impl<S> Freeze for SmtpClient<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for SmtpClient<S>
where S: RefUnwindSafe,

§

impl<S> Send for SmtpClient<S>
where S: Send,

§

impl<S> Sync for SmtpClient<S>
where S: Sync,

§

impl<S> Unpin for SmtpClient<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for SmtpClient<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for SmtpClient<S>
where S: UnwindSafe,

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<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.