fix(smtp) Allow forcing of a specific auth
@@ -96,6 +96,8 @@ pub struct SmtpClient {
smtp_utf8: bool,
/// Optional enforced authentication mechanism
authentication_mechanism: Option<Mechanism>,
+ /// Force use of the set authentication mechanism even if server does not report to support it
+ force_set_auth: bool,
/// Define network timeout
/// It can be changed later for specific needs (like a different timeout for each SMTP command)
timeout: Option<Duration>,
@@ -125,6 +127,7 @@ impl SmtpClient {
connection_reuse: ConnectionReuseParameters::NoReuse,
hello_name: ClientId::hostname(),
authentication_mechanism: None,
+ force_set_auth: false,
timeout: Some(Duration::new(60, 0)),
}),
None => Err(Error::Resolution),
@@ -182,6 +185,12 @@ impl SmtpClient {
self
}
+ /// Set if the set authentication mechanism should be force
+ pub fn force_set_auth(mut self, force: bool) -> SmtpClient {
+ self.force_set_auth = force;
+ self
+ }
+
/// Set the timeout duration
pub fn timeout(mut self, timeout: Option<Duration>) -> SmtpClient {
self.timeout = timeout;
@@ -311,6 +320,7 @@ impl<'a> SmtpTransport {
if self.client_info.credentials.is_some() {
let mut found = false;
+ if !self.client_info.force_set_auth {
// Compute accepted mechanism
let accepted_mechanisms = match self.client_info.authentication_mechanism {
Some(mechanism) => vec![mechanism],
@@ -339,6 +349,14 @@ impl<'a> SmtpTransport {
break;
}
}
+ } else {
+ try_smtp!(
+ self.client.auth(self.client_info.authentication_mechanism.expect(
+ "force_set_auth set to true, but no authentication mechanism set"), self.client_info.credentials.as_ref().unwrap(),),
+ self
+ );
+ found = true;
+ }
if !found {
info!("No supported authentication mechanisms available");
