[PR #7740/671b7ab1 backport][stable-8] mail module: add Message-ID header (#7764)
mail module: add Message-ID header (#7740)
* mail module: add Message-ID header
* Update plugins/modules/mail.py
Co-authored-by: Felix Fontein <felix@fontein.de>
---------
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 671b7ab149
)
Co-authored-by: Sébastien Bocahu <sebastien+github@bocahu.name>
pull/7768/head
parent
5dc20d9028
commit
21a7159472
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- mail - add ``Message-ID`` header; which is required by some mail servers (https://github.com/ansible-collections/community.general/pull/7740).
|
|
@ -222,7 +222,7 @@ import smtplib
|
|||
import ssl
|
||||
import traceback
|
||||
from email import encoders
|
||||
from email.utils import parseaddr, formataddr, formatdate
|
||||
from email.utils import parseaddr, formataddr, formatdate, make_msgid
|
||||
from email.mime.base import MIMEBase
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
|
@ -349,6 +349,11 @@ def main():
|
|||
msg['From'] = formataddr((sender_phrase, sender_addr))
|
||||
msg['Date'] = formatdate(localtime=True)
|
||||
msg['Subject'] = Header(subject, charset)
|
||||
try:
|
||||
msg['Message-ID'] = make_msgid(domain='ansible')
|
||||
except TypeError:
|
||||
# `domain` is only available in Python 3
|
||||
msg['Message-ID'] = make_msgid()
|
||||
msg.preamble = "Multipart message"
|
||||
|
||||
for header in headers:
|
||||
|
|
Loading…
Reference in New Issue