Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
[rapydo/issues#36] Fix send mail, wrong type passed to smtp
Browse files Browse the repository at this point in the history
Fix date format in email header
  • Loading branch information
Mattia D'Antonio committed Nov 6, 2017
1 parent a5c884e commit 37fafcb
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions utilities/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from smtplib import SMTP, SMTPException
from email.mime.text import MIMEText
import datetime
import pytz

from utilities.logs import get_logger

Expand All @@ -36,11 +37,13 @@ def send_mail(body, subject,
return False

try:

date_fmt = "%a, %b %d, %Y at %I:%M %p %z"
msg = MIMEText(body)
msg['Subject'] = subject
msg['From'] = from_address
msg['To'] = to_address
msg['Date'] = datetime.datetime.now().strftime("%d/%m/%Y %H:%M")
msg['Date'] = datetime.datetime.now(pytz.utc).strftime(date_fmt)

smtp = SMTP()
smtp.set_debuglevel(0)
Expand All @@ -52,7 +55,7 @@ def send_mail(body, subject,

try:
log.verbose("Sending email to %s", to_address)
smtp.sendmail(from_address, to_address, msg)
smtp.sendmail(from_address, to_address, msg.as_string())
log.info("Successfully sent email to %s", to_address)
smtp.quit()
return True
Expand Down

0 comments on commit 37fafcb

Please sign in to comment.