Expose test_connected via transport (#677)

It is useful for application developers to validate SMTP
settings by testing the connection.

Co-authored-by: Alexis Mousset <contact@amousset.me>
This commit is contained in:
Filip Gospodinov
2021-10-20 16:42:49 +02:00
committed by GitHub
parent 97d3c760c0
commit 592593f4b8
2 changed files with 30 additions and 0 deletions

View File

@@ -167,6 +167,21 @@ where
pool_config: PoolConfig::default(),
}
}
/// Tests the SMTP connection
///
/// `test_connection()` tests the connection by using the SMTP NOOP command.
/// The connection is closed afterwards if a connection pool is not used.
pub async fn test_connection(&self) -> Result<bool, Error> {
let mut conn = self.inner.connection().await?;
let is_connected = conn.test_connected().await;
#[cfg(not(feature = "pool"))]
conn.quit().await?;
Ok(is_connected)
}
}
impl<E: Executor> Debug for AsyncSmtpTransport<E> {

View File

@@ -107,6 +107,21 @@ impl SmtpTransport {
pool_config: PoolConfig::default(),
}
}
/// Tests the SMTP connection
///
/// `test_connection()` tests the connection by using the SMTP NOOP command.
/// The connection is closed afterwards if a connection pool is not used.
pub fn test_connection(&self) -> Result<bool, Error> {
let mut conn = self.inner.connection()?;
let is_connected = conn.test_connected();
#[cfg(not(feature = "pool"))]
conn.quit()?;
Ok(is_connected)
}
}
/// Contains client configuration.