diff --git a/mail_client/mail_client/doctype/outgoing_mail/outgoing_mail.py b/mail_client/mail_client/doctype/outgoing_mail/outgoing_mail.py index 2d67e0d8..dc4629a2 100644 --- a/mail_client/mail_client/doctype/outgoing_mail/outgoing_mail.py +++ b/mail_client/mail_client/doctype/outgoing_mail/outgoing_mail.py @@ -666,7 +666,10 @@ def transfer_to_mail_server(self) -> None: message["X-Priority"] = "3" message = message.as_string() - recipients = list(set([rcpt.email for rcpt in self.recipients])) + # Remove duplicate recipients while preserving the order by using `dict.fromkeys()`. + # This avoids using a set, which could change the order of recipients. + recipients = list(dict.fromkeys([rcpt.email for rcpt in self.recipients])) + outbound_api = get_mail_server_outbound_api() token = outbound_api.send(self.name, recipients, message)