fix message for more than one recipient

Signed-off-by: Florian Brandes <florian.brandes@posteo.de>
This commit is contained in:
2024-07-12 20:34:29 +02:00
parent d00a45849e
commit e860cf24f1

View File

@@ -316,13 +316,18 @@ class SMTPClient(SMTP):
f"'{message.get('Subject', '')}'"
)
if self._config.smime_cert and self._emails.email_certs[recipient] != "":
message = self._encrypt_and_sign(message, recipient)
m = self._encrypt_and_sign(message, recipient)
else:
m = message
m.add_header("From", self._config.sender)
m.add_header("To", recipient)
m = m.as_bytes()
async with (
self._lock
): # TODO: consumer task from spool queue, reusing connections
try:
await self.connect()
await self._send_message(message, self._config.sender, recipient)
await self._send_message(m, self._config.sender, recipient)
except SMTPRecipientsRefused as e:
raise RuntimeError(
f"Recipients refused: {', '.join(_.recipient for _ in e.recipients)}"