diff --git a/src/smtp.rs b/src/smtp.rs index 23c68e9bd..990e15203 100644 --- a/src/smtp.rs +++ b/src/smtp.rs @@ -431,10 +431,16 @@ pub(crate) async fn send_msg_to_smtp( let mut recipients = queued_mail.recipients.clone(); if queued_mail.bcc_self { + let from_addr = smtp + .from + .as_ref() + .context("No From address available, likely not connected")? + .to_string(); add_self_recipients( context, &mut recipients, queued_mail.encryption.is_encrypted(), + from_addr, ) .await .context("Failed to add self recipients")?; @@ -703,7 +709,7 @@ async fn send_mdn_rfc724_mid( let body = rendered_msg.message; if context.get_config_bool(Config::BccSelf).await? { - add_self_recipients(context, &mut recipients, encrypted).await?; + add_self_recipients(context, &mut recipients, encrypted, from).await?; } let recipients: Vec<_> = recipients .into_iter() @@ -820,11 +826,11 @@ pub(crate) async fn add_self_recipients( context: &Context, recipients: &mut Vec, encrypted: bool, + from: String, ) -> Result<()> { // Avoid sending unencrypted messages to all transports, // chatmail relays won't accept them. Normally the user should have // a non-chatmail sending transport to send unencrypted messages. - let from = context.get_primary_self_addr().await?; if encrypted { for addr in context.get_self_addrs().await? { if addr != from { diff --git a/src/test_utils.rs b/src/test_utils.rs index 4e6ca6150..b7c03ce69 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -632,10 +632,15 @@ ORDER BY id" .await .expect("Failed to load queued mail"); if queued_mail.bcc_self { + let from = self + .get_primary_self_addr() + .await + .expect("Cannot get From address"); smtp::add_self_recipients( &self.ctx, &mut queued_mail.recipients, queued_mail.encryption.is_encrypted(), + from, ) .await .expect("Failed to add self recipients"); @@ -729,10 +734,15 @@ ORDER BY id" .await .expect("Failed to load queued mail"); if queued_mail.bcc_self { + let from = self + .get_primary_self_addr() + .await + .expect("Cannot get self address"); smtp::add_self_recipients( &self.ctx, &mut queued_mail.recipients, queued_mail.encryption.is_encrypted(), + from, ) .await .expect("Failed to add self recipients");