diff --git a/changelogs/fragments/4056-add-missing-mail-headers.yml b/changelogs/fragments/4056-add-missing-mail-headers.yml new file mode 100644 index 0000000000..fefa655f72 --- /dev/null +++ b/changelogs/fragments/4056-add-missing-mail-headers.yml @@ -0,0 +1,2 @@ +minor_changes: + - mail callback plugin - add ``Message-ID`` and ``Date`` headers (https://github.com/ansible-collections/community.general/issues/4055, https://github.com/ansible-collections/community.general/pull/4056). diff --git a/plugins/callback/mail.py b/plugins/callback/mail.py index 8d437c8d23..deaff6a03f 100644 --- a/plugins/callback/mail.py +++ b/plugins/callback/mail.py @@ -59,6 +59,7 @@ notes: import json import os import re +import email.utils import smtplib from ansible.module_utils.six import string_types @@ -100,10 +101,12 @@ class CallbackModule(CallbackBase): smtp = smtplib.SMTP(self.smtphost, port=self.smtpport) - content = 'From: %s\n' % self.sender + content = 'Date: %s\n' % email.utils.formatdate() + content += 'From: %s\n' % self.sender content += 'To: %s\n' % self.to if self.cc: content += 'Cc: %s\n' % self.cc + content += 'Message-ID: %s\n' % email.utils.make_msgid() content += 'Subject: %s\n\n' % subject.strip() content += body