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

mail: adding capability to specify ehlo hostname (#3425)

* Adding capability to specify ehlo hostname

* Fixing default for ehlohost

the CI did not like "None" as default in the documentation,
judging from the rest of the definitions omitting that seems to be right

* Update plugins/modules/notification/mail.py

Proper spelling in documentation

Co-authored-by: Ajpantuso <ajpantuso@gmail.com>

* Adding Changelog Fragment

* Update changelogs/fragments/3425-mail_add_configurable_ehlo_hostname.yml

Proper phrasing in changelog

Co-authored-by: Ajpantuso <ajpantuso@gmail.com>

* integration-test for ehlohost parameter

* proper description, increased async-time

changed body of ehlohost-mail to reflect ehlohost
increased async from 30 to 45 as CI failed because
smtp was already down.

Co-authored-by: Ajpantuso <ajpantuso@gmail.com>
This commit is contained in:
Hartwig Hauschild 2021-09-24 07:30:14 +02:00 committed by GitHub
parent e1cdad3537
commit ae6cbc2d82
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 5 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- mail - added the ``ehlohost`` parameter which allows for manual override of the host used in SMTP EHLO (https://github.com/ansible-collections/community.general/pull/3425).

View file

@ -125,6 +125,11 @@ options:
- Sets the timeout in seconds for connection attempts. - Sets the timeout in seconds for connection attempts.
type: int type: int
default: 20 default: 20
ehlohost:
description:
- Allows for manual specification of host for EHLO.
type: str
version_added: 3.8.0
''' '''
EXAMPLES = r''' EXAMPLES = r'''
@ -189,6 +194,16 @@ EXAMPLES = r'''
subject: Ansible-report subject: Ansible-report
body: System {{ ansible_hostname }} has been successfully provisioned. body: System {{ ansible_hostname }} has been successfully provisioned.
secure: starttls secure: starttls
- name: Sending an e-mail using StartTLS, remote server, custom EHLO
community.general.mail:
host: some.smtp.host.tld
port: 25
ehlohost: my-resolvable-hostname.tld
to: John Smith <john.smith@example.com>
subject: Ansible-report
body: System {{ ansible_hostname }} has been successfully provisioned.
secure: starttls
''' '''
import os import os
@ -215,6 +230,7 @@ def main():
password=dict(type='str', no_log=True), password=dict(type='str', no_log=True),
host=dict(type='str', default='localhost'), host=dict(type='str', default='localhost'),
port=dict(type='int', default=25), port=dict(type='int', default=25),
ehlohost=dict(type='str', default=None),
sender=dict(type='str', default='root', aliases=['from']), sender=dict(type='str', default='root', aliases=['from']),
to=dict(type='list', elements='str', default=['root'], aliases=['recipients']), to=dict(type='list', elements='str', default=['root'], aliases=['recipients']),
cc=dict(type='list', elements='str', default=[]), cc=dict(type='list', elements='str', default=[]),
@ -235,6 +251,7 @@ def main():
password = module.params.get('password') password = module.params.get('password')
host = module.params.get('host') host = module.params.get('host')
port = module.params.get('port') port = module.params.get('port')
local_hostname = module.params.get('ehlohost')
sender = module.params.get('sender') sender = module.params.get('sender')
recipients = module.params.get('to') recipients = module.params.get('to')
copies = module.params.get('cc') copies = module.params.get('cc')
@ -259,9 +276,9 @@ def main():
if secure != 'never': if secure != 'never':
try: try:
if PY3: if PY3:
smtp = smtplib.SMTP_SSL(host=host, port=port, timeout=timeout) smtp = smtplib.SMTP_SSL(host=host, port=port, local_hostname=local_hostname, timeout=timeout)
else: else:
smtp = smtplib.SMTP_SSL(timeout=timeout) smtp = smtplib.SMTP_SSL(local_hostname=local_hostname, timeout=timeout)
code, smtpmessage = smtp.connect(host, port) code, smtpmessage = smtp.connect(host, port)
secure_state = True secure_state = True
except ssl.SSLError as e: except ssl.SSLError as e:
@ -273,9 +290,9 @@ def main():
if not secure_state: if not secure_state:
if PY3: if PY3:
smtp = smtplib.SMTP(host=host, port=port, timeout=timeout) smtp = smtplib.SMTP(host=host, port=port, local_hostname=local_hostname, timeout=timeout)
else: else:
smtp = smtplib.SMTP(timeout=timeout) smtp = smtplib.SMTP(local_hostname=local_hostname, timeout=timeout)
code, smtpmessage = smtp.connect(host, port) code, smtpmessage = smtp.connect(host, port)
except smtplib.SMTPException as e: except smtplib.SMTPException as e:

View file

@ -26,7 +26,7 @@
# This would require either dumping the content, or registering async task output # This would require either dumping the content, or registering async task output
- name: Start test smtpserver - name: Start test smtpserver
shell: '{{ ansible_python.executable }} {{ remote_tmp_dir }}/smtpserver.py 10025:10465' shell: '{{ ansible_python.executable }} {{ remote_tmp_dir }}/smtpserver.py 10025:10465'
async: 30 async: 45
poll: 0 poll: 0
register: smtpserver register: smtpserver
@ -88,3 +88,13 @@
- fail: - fail:
msg: Send mail using TLS failed. msg: Send mail using TLS failed.
when: smtpd_tls is succeeded and tls_support is failed and starttls_support is succeeded when: smtpd_tls is succeeded and tls_support is failed and starttls_support is succeeded
- name: Send a test-mail with body, specific recipient and specific ehlohost
mail:
port: 10025
ehlohost: some.domain.tld
from: ansible@localhost
to: root@localhost
subject: Test mail 6 (smtp + body + ehlohost)
body: Test body 6
secure: never