Skip to content

Commit

Permalink
Use email.policy.default in Python 3 implementation
Browse files Browse the repository at this point in the history
Improves standards compatibility and utf-8 handling
in Python 3.3-3.8. (email.policy.default becomes the
default in Python 3.9.)
  • Loading branch information
medmunds committed Feb 17, 2021
1 parent 8f688e5 commit 28d9f00
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions notify/smtp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,11 @@ _smtp_send_python() {
try:
try:
from email.message import EmailMessage
from email.policy import default as email_policy_default
except ImportError:
from email.mime.text import MIMEText as EmailMessage # Python 2
# Python 2 (or < 3.3)
from email.mime.text import MIMEText as EmailMessage
email_policy_default = None
from email.utils import formatdate as rfc2822_date
from smtplib import SMTP, SMTP_SSL, SMTPException
from socket import error as SocketError
Expand All @@ -311,7 +314,7 @@ subject="""$SMTP_SUBJECT"""
content="""$SMTP_CONTENT"""
try:
msg = EmailMessage()
msg = EmailMessage(policy=email_policy_default)
msg.set_content(content)
except (AttributeError, TypeError):
# Python 2 MIMEText
Expand Down

0 comments on commit 28d9f00

Please sign in to comment.