mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
mail module/callback: allow to configure the Message-ID header's domain name (#7765)
Allow to configure the Message-ID header's domain name.
This commit is contained in:
parent
08ece2e0fa
commit
acddb190ba
3 changed files with 24 additions and 2 deletions
2
changelogs/fragments/7765-mail-message-id.yml
Normal file
2
changelogs/fragments/7765-mail-message-id.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- "mail module, mail callback plugin - allow to configure the domain name of the Message-ID header with a new ``message_id_domain`` option (https://github.com/ansible-collections/community.general/pull/7765)."
|
|
@ -71,6 +71,16 @@ options:
|
||||||
ini:
|
ini:
|
||||||
- section: callback_mail
|
- section: callback_mail
|
||||||
key: bcc
|
key: bcc
|
||||||
|
message_id_domain:
|
||||||
|
description:
|
||||||
|
- The domain name to use for the L(Message-ID header, https://en.wikipedia.org/wiki/Message-ID).
|
||||||
|
- The default is the hostname of the control node.
|
||||||
|
type: str
|
||||||
|
ini:
|
||||||
|
- section: callback_mail
|
||||||
|
key: message_id_domain
|
||||||
|
version_added: 8.2.0
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
@ -131,7 +141,7 @@ class CallbackModule(CallbackBase):
|
||||||
content += 'To: %s\n' % ', '.join([email.utils.formataddr(pair) for pair in to_addresses])
|
content += 'To: %s\n' % ', '.join([email.utils.formataddr(pair) for pair in to_addresses])
|
||||||
if self.cc:
|
if self.cc:
|
||||||
content += 'Cc: %s\n' % ', '.join([email.utils.formataddr(pair) for pair in cc_addresses])
|
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(domain=self.get_option('message_id_domain'))
|
||||||
content += 'Subject: %s\n\n' % subject.strip()
|
content += 'Subject: %s\n\n' % subject.strip()
|
||||||
content += body
|
content += body
|
||||||
|
|
||||||
|
|
|
@ -140,6 +140,13 @@ options:
|
||||||
- Allows for manual specification of host for EHLO.
|
- Allows for manual specification of host for EHLO.
|
||||||
type: str
|
type: str
|
||||||
version_added: 3.8.0
|
version_added: 3.8.0
|
||||||
|
message_id_domain:
|
||||||
|
description:
|
||||||
|
- The domain name to use for the L(Message-ID header, https://en.wikipedia.org/wiki/Message-ID).
|
||||||
|
- Note that this is only available on Python 3+. On Python 2, this value will be ignored.
|
||||||
|
type: str
|
||||||
|
default: ansible
|
||||||
|
version_added: 8.2.0
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r'''
|
||||||
|
@ -254,6 +261,7 @@ def main():
|
||||||
subtype=dict(type='str', default='plain', choices=['html', 'plain']),
|
subtype=dict(type='str', default='plain', choices=['html', 'plain']),
|
||||||
secure=dict(type='str', default='try', choices=['always', 'never', 'starttls', 'try']),
|
secure=dict(type='str', default='try', choices=['always', 'never', 'starttls', 'try']),
|
||||||
timeout=dict(type='int', default=20),
|
timeout=dict(type='int', default=20),
|
||||||
|
message_id_domain=dict(type='str', default='ansible'),
|
||||||
),
|
),
|
||||||
required_together=[['password', 'username']],
|
required_together=[['password', 'username']],
|
||||||
)
|
)
|
||||||
|
@ -275,6 +283,7 @@ def main():
|
||||||
subtype = module.params.get('subtype')
|
subtype = module.params.get('subtype')
|
||||||
secure = module.params.get('secure')
|
secure = module.params.get('secure')
|
||||||
timeout = module.params.get('timeout')
|
timeout = module.params.get('timeout')
|
||||||
|
message_id_domain = module.params['message_id_domain']
|
||||||
|
|
||||||
code = 0
|
code = 0
|
||||||
secure_state = False
|
secure_state = False
|
||||||
|
@ -350,10 +359,11 @@ def main():
|
||||||
msg['Date'] = formatdate(localtime=True)
|
msg['Date'] = formatdate(localtime=True)
|
||||||
msg['Subject'] = Header(subject, charset)
|
msg['Subject'] = Header(subject, charset)
|
||||||
try:
|
try:
|
||||||
msg['Message-ID'] = make_msgid(domain='ansible')
|
msg['Message-ID'] = make_msgid(domain=message_id_domain)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# `domain` is only available in Python 3
|
# `domain` is only available in Python 3
|
||||||
msg['Message-ID'] = make_msgid()
|
msg['Message-ID'] = make_msgid()
|
||||||
|
module.warn("The Message-ID domain cannot be set on Python 2; the system's hostname is used")
|
||||||
msg.preamble = "Multipart message"
|
msg.preamble = "Multipart message"
|
||||||
|
|
||||||
for header in headers:
|
for header in headers:
|
||||||
|
|
Loading…
Reference in a new issue