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) (#4063)

(cherry picked from commit c7500c217f)

Co-authored-by: Lénaïc Huard <L3n41c@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2022-01-20 09:30:06 +01:00 committed by GitHub
parent 5f20d7f109
commit 08eac051f4
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) smtp = smtplib.SMTP(self.smtphost, port=self.smtpport)
b_sender = to_bytes(self.sender) content = 'From: %s\n' % self.sender
b_to = to_bytes(self.to) content += 'To: %s\n' % 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
if self.cc: if self.cc:
b_content += b'Cc: %s\n' % b_cc content += 'Cc: %s\n' % self.cc
b_content += b'Subject: %s\n\n' % b_subject content += 'Subject: %s\n\n' % subject.strip()
b_content += b_body content += body
b_addresses = b_to.split(b',') addresses = self.to.split(',')
if self.cc: if self.cc:
b_addresses += b_cc.split(b',') addresses += self.cc.split(',')
if self.bcc: if self.bcc:
b_addresses += b_bcc.split(b',') addresses += self.bcc.split(',')
for b_address in b_addresses: for address in addresses:
smtp.sendmail(b_sender, b_address, b_content) smtp.sendmail(self.sender, address, to_bytes(content))
smtp.quit() smtp.quit()