mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
mail: fix the encoding of the mail senders and recipients name (#4061)
This commit is contained in:
parent
f5ec73735f
commit
8682ac96df
2 changed files with 18 additions and 9 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- mail callback plugin - fix encoding of the name of sender and recipient (https://github.com/ansible-collections/community.general/issues/4060, https://github.com/ansible-collections/community.general/pull/4061).
|
|
@ -120,27 +120,34 @@ class CallbackModule(CallbackBase):
|
||||||
|
|
||||||
smtp = smtplib.SMTP(self.smtphost, port=self.smtpport)
|
smtp = smtplib.SMTP(self.smtphost, port=self.smtpport)
|
||||||
|
|
||||||
content = 'Date: %s\n' % email.utils.formatdate()
|
sender_address = email.utils.parseaddr(self.sender)
|
||||||
content += 'From: %s\n' % self.sender
|
|
||||||
if self.to:
|
if self.to:
|
||||||
content += 'To: %s\n' % ','.join(self.to)
|
to_addresses = email.utils.getaddresses(self.to)
|
||||||
if self.cc:
|
if self.cc:
|
||||||
content += 'Cc: %s\n' % ','.join(self.cc)
|
cc_addresses = email.utils.getaddresses(self.cc)
|
||||||
|
if self.bcc:
|
||||||
|
bcc_addresses = email.utils.getaddresses(self.bcc)
|
||||||
|
|
||||||
|
content = 'Date: %s\n' % email.utils.formatdate()
|
||||||
|
content += 'From: %s\n' % email.utils.formataddr(sender_address)
|
||||||
|
if self.to:
|
||||||
|
content += 'To: %s\n' % ', '.join([email.utils.formataddr(pair) for pair in to_addresses])
|
||||||
|
if self.cc:
|
||||||
|
content += 'Cc: %s\n' % ', '.join([email.utils.formataddr(pair) for pair in cc_addresses])
|
||||||
content += 'Message-ID: %s\n' % email.utils.make_msgid()
|
content += 'Message-ID: %s\n' % email.utils.make_msgid()
|
||||||
content += 'Subject: %s\n\n' % subject.strip()
|
content += 'Subject: %s\n\n' % subject.strip()
|
||||||
content += body
|
content += body
|
||||||
|
|
||||||
addresses = self.to
|
addresses = to_addresses
|
||||||
if self.cc:
|
if self.cc:
|
||||||
addresses += self.cc
|
addresses += cc_addresses
|
||||||
if self.bcc:
|
if self.bcc:
|
||||||
addresses += self.bcc
|
addresses += bcc_addresses
|
||||||
|
|
||||||
if not addresses:
|
if not addresses:
|
||||||
self._display.warning('No receiver has been specified for the mail callback plugin.')
|
self._display.warning('No receiver has been specified for the mail callback plugin.')
|
||||||
|
|
||||||
for address in addresses:
|
smtp.sendmail(self.sender, [address for name, address in addresses], to_bytes(content))
|
||||||
smtp.sendmail(self.sender, address, to_bytes(content))
|
|
||||||
|
|
||||||
smtp.quit()
|
smtp.quit()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue