Repository: ansible/ansible
Pull request: Module mail : Add Date header
##### SUMMARY
Add Date header for emails sent by email module
Fixes #58808

##### ISSUE TYPE
- Feature Pull Request

##### COMPONENT NAME
mail

##### ADDITIONAL INFORMATION
Add Date header to the email.
This header is "nice to have" if you need to send out your emails on Internet


Problem statement:
mail module should send email with "Date" header
<!--- Verify first that your issue is not already reported on GitHub -->
<!--- Also test if the latest release and devel branch are affected too -->
<!--- Complete *all* sections as described, this form is processed automatically -->

##### SUMMARY
mail module does not send email with Date header. It should send email with "Date" header automatically without any manual email header manipulation.

##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
mail

##### ANSIBLE VERSION
```
ansible 2.8.1
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/yclee/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.15+ (default, Nov 27 2018, 23:36:35) [GCC 7.3.0]
```

##### CONFIGURATION
(None)

##### OS / ENVIRONMENT
Ubuntu 18.04

##### STEPS TO REPRODUCE
N/A

##### EXPECTED RESULTS
email should have Date headers

##### ACTUAL RESULTS
email did not  have Date headers and I have to manually insert it

Hints from issue discussion:
Files identified in the description:
* [`lib/ansible/modules/notification/mail.py`](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/notification/mail.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @dagwieers
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Commit message: Mail module : add date header (#58808)

Patch to review:
diff --git a/changelogs/fragments/58808-mail-add-date-header.yaml b/changelogs/fragments/58808-mail-add-date-header.yaml
new file mode 100644
index 00000000000000..a3906a6181aba5
--- /dev/null
+++ b/changelogs/fragments/58808-mail-add-date-header.yaml
@@ -0,0 +1,2 @@
+minor_changes:
+  - add date header to the email based on local time
diff --git a/lib/ansible/modules/notification/mail.py b/lib/ansible/modules/notification/mail.py
index 057f826bf66743..bae57ff2749e99 100644
--- a/lib/ansible/modules/notification/mail.py
+++ b/lib/ansible/modules/notification/mail.py
@@ -203,7 +203,7 @@
 import ssl
 import traceback
 from email import encoders
-from email.utils import parseaddr, formataddr
+from email.utils import parseaddr, formataddr, formatdate
 from email.mime.base import MIMEBase
 from email.mime.multipart import MIMEMultipart
 from email.mime.text import MIMEText
@@ -326,6 +326,7 @@ def main():
 
     msg = MIMEMultipart(_charset=charset)
     msg['From'] = formataddr((sender_phrase, sender_addr))
+    msg['Date'] = formatdate(localtime=True)
     msg['Subject'] = Header(subject, charset)
     msg.preamble = "Multipart message"
 


Code review comments:
diff_hunk: @@ -0,0 +1,2 @@
+minor_changes:
+  - add date header to the email based on local time
path: changelogs/fragments/58808-mail-add-date-header.yaml
text: @user1:
```suggestion
  - Add date header to the email based on local time in mail module (https://github.com/ansible/ansible/issues/58808).
```

@author:
Thanks for the review.
I improved the changelog as suggested.