Skip to content

Commit

Permalink
可自定义邮件服务器
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris-code committed May 10, 2021
1 parent b950eaa commit a9d3564
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions feapder/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
EAMIL_SENDER = "" # 发件人
EAMIL_PASSWORD = "" # 授权码
EMAIL_RECEIVER = "" # 收件人 支持列表,可指定多个
EMAIL_SMTPSERVER = "smtp.163.com" # 邮件服务器 默认为163邮箱
# 企业微信报警
WECHAT_WARNING_URL = "" # 企业微信机器人api
WECHAT_WARNING_PHONE = "" # 报警人 将会在群内@此人, 支持列表,可指定多人
Expand Down
1 change: 1 addition & 0 deletions feapder/templates/project_template/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
# EAMIL_SENDER = "" # 发件人
# EAMIL_PASSWORD = "" # 授权码
# EMAIL_RECEIVER = "" # 收件人 支持列表,可指定多个
# EMAIL_SMTPSERVER = "smtp.163.com" # 邮件服务器 默认为163邮箱
# # 企业微信报警
# WECHAT_WARNING_URL = "" # 企业微信机器人api
# WECHAT_WARNING_PHONE = "" # 报警人 将会在群内@此人, 支持列表,可指定多人
Expand Down
8 changes: 3 additions & 5 deletions feapder/utils/email_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@

class EmailSender(object):
SENDER = "feapder报警系统"
SMTPSERVER = "smtp.163.com"

def __init__(self, username, password):
def __init__(self, username, password, smtpserver="smtp.163.com"):
self.username = username
self.password = password

self.smtpserver = EmailSender.SMTPSERVER
self.smtpserver = smtpserver
self.smtp_client = smtplib.SMTP_SSL(smtpserver)
self.sender = EmailSender.SENDER
self.smtp_client = smtplib.SMTP_SSL(self.SMTPSERVER)

def __enter__(self):
self.login()
Expand Down
7 changes: 5 additions & 2 deletions feapder/utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2267,6 +2267,7 @@ def email_warning(
eamil_sender=setting.EAMIL_SENDER,
eamil_password=setting.EAMIL_PASSWORD,
email_receiver=setting.EMAIL_RECEIVER,
email_smtpserver=setting.EMAIL_SMTPSERVER,
rate_limit=setting.WARNING_INTERVAL,
):
if not all([message, eamil_sender, eamil_password, email_receiver]):
Expand All @@ -2281,7 +2282,9 @@ def email_warning(
if isinstance(email_receiver, str):
email_receiver = [email_receiver]

with EmailSender(username=eamil_sender, password=eamil_password) as email:
with EmailSender(
username=eamil_sender, password=eamil_password, smtpserver=email_smtpserver
) as email:
return email.send(receivers=email_receiver, title=title, content=message)


Expand Down Expand Up @@ -2366,4 +2369,4 @@ def make_item(cls, data: dict):
item = cls()
for key, val in data.items():
setattr(item, key, val)
return item
return item

0 comments on commit a9d3564

Please sign in to comment.