1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fix exception in the mail callback plugin (#4026)

This commit is contained in:
Lénaïc Huard 2022-01-20 08:31:09 +01:00 committed by GitHub
parent c18fdb43d7
commit c7500c217f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 17 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- mail callback plugin - fix crash on Python 3 (https://github.com/ansible-collections/community.general/issues/4025, https://github.com/ansible-collections/community.general/pull/4026).

View file

@ -100,28 +100,21 @@ class CallbackModule(CallbackBase):
smtp = smtplib.SMTP(self.smtphost, port=self.smtpport)
b_sender = to_bytes(self.sender)
b_to = to_bytes(self.to)
b_cc = to_bytes(self.cc)
b_bcc = to_bytes(self.bcc)
b_subject = to_bytes(subject)
b_body = to_bytes(body)
b_content = b'From: %s\n' % b_sender
b_content += b'To: %s\n' % b_to
content = 'From: %s\n' % self.sender
content += 'To: %s\n' % self.to
if self.cc:
b_content += b'Cc: %s\n' % b_cc
b_content += b'Subject: %s\n\n' % b_subject
b_content += b_body
content += 'Cc: %s\n' % self.cc
content += 'Subject: %s\n\n' % subject.strip()
content += body
b_addresses = b_to.split(b',')
addresses = self.to.split(',')
if self.cc:
b_addresses += b_cc.split(b',')
addresses += self.cc.split(',')
if self.bcc:
b_addresses += b_bcc.split(b',')
addresses += self.bcc.split(',')
for b_address in b_addresses:
smtp.sendmail(b_sender, b_address, b_content)
for address in addresses:
smtp.sendmail(self.sender, address, to_bytes(content))
smtp.quit()