Skip to content

Commit

Permalink
邮件支持配置SSL
Browse files Browse the repository at this point in the history
  • Loading branch information
hhyo committed Aug 3, 2018
1 parent 85ad59b commit 89d935a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions archer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
# 'level': 'DEBUG',
# 'propagate': False,
# },
'django.request': { # 打印SQL语句到console,方便开发
'django.request': { # 打印错误堆栈信息到console,方便开发
'handlers': ['console'],
'level': 'DEBUG',
'propagate': False,
Expand All @@ -244,7 +244,7 @@

# 是否开启邮件提醒功能:发起SQL上线后会发送邮件提醒审核人审核,执行完毕会发送给DBA. on是开,off是关,配置为其他值均会被archer认为不开启邮件功能
MAIL_ON_OFF = 'off'

MAIL_SSL = False # 是否使用SSL
MAIL_REVIEW_SMTP_SERVER = 'mail.xxx.com'
MAIL_REVIEW_SMTP_PORT = 25
MAIL_REVIEW_FROM_ADDR = '[email protected]' # 发件人,也是登录SMTP server需要提供的用户名
Expand Down
6 changes: 5 additions & 1 deletion sql/sendmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self):
self.MAIL_REVIEW_SMTP_PORT = int(getattr(settings, 'MAIL_REVIEW_SMTP_PORT'))
self.MAIL_REVIEW_FROM_ADDR = getattr(settings, 'MAIL_REVIEW_FROM_ADDR')
self.MAIL_REVIEW_FROM_PASSWORD = getattr(settings, 'MAIL_REVIEW_FROM_PASSWORD')
self.SSL = getattr(settings, 'MAIL_SSL')

except AttributeError as a:
print("Error: %s" % a)
Expand Down Expand Up @@ -72,7 +73,10 @@ def _send(self, strTitle, strContent, listToAddr, **kwargs):
main_msg['Subject'] = Header(strTitle, "utf-8").encode()
main_msg['Date'] = email.utils.formatdate()

server = smtplib.SMTP(self.MAIL_REVIEW_SMTP_SERVER, self.MAIL_REVIEW_SMTP_PORT) # SMTP协议默认端口是25
if self.SSL:
server = smtplib.SMTP_SSL(self.MAIL_REVIEW_SMTP_SERVER, self.MAIL_REVIEW_SMTP_PORT) # SMTP协议默认SSL端口是465
else:
server = smtplib.SMTP(self.MAIL_REVIEW_SMTP_SERVER, self.MAIL_REVIEW_SMTP_PORT) # SMTP协议默认端口是25
# server.set_debuglevel(1)

# 如果提供的密码为空,则不需要登录SMTP server
Expand Down

0 comments on commit 89d935a

Please sign in to comment.