Skip to content

Commit b73af4c

Browse files
authored
Merge pull request millylee#35 from jerryscription/main
增加支持自定义SMTP服务器的设置
2 parents b96db2b + ce2dc6f commit b73af4c

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

.github/workflows/checkin.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ jobs:
7676
EMAIL_USER: ${{ secrets.EMAIL_USER }}
7777
EMAIL_PASS: ${{ secrets.EMAIL_PASS }}
7878
EMAIL_TO: ${{ secrets.EMAIL_TO }}
79+
CUSTOM_SMTP_SERVER: ${{ secrets.CUSTOM_SMTP_SERVER }}
7980
PUSHPLUS_TOKEN: ${{ secrets.PUSHPLUS_TOKEN }}
8081
SERVERPUSHKEY: ${{ secrets.SERVERPUSHKEY }}
8182
FEISHU_WEBHOOK: ${{ secrets.FEISHU_WEBHOOK }}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@
143143
### 邮箱通知
144144
- `EMAIL_USER`: 发件人邮箱地址
145145
- `EMAIL_PASS`: 发件人邮箱密码/授权码
146+
- `CUSTOM_SMTP_SERVER`: 自定义发件人SMTP服务器(可选)
146147
- `EMAIL_TO`: 收件人邮箱地址
147-
148148
### 钉钉机器人
149149
- `DINGDING_WEBHOOK`: 钉钉机器人的 Webhook 地址
150150

notify.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def __init__(self):
1212
self.email_user: str = os.getenv('EMAIL_USER', '')
1313
self.email_pass: str = os.getenv('EMAIL_PASS', '')
1414
self.email_to: str = os.getenv('EMAIL_TO', '')
15+
self.smtp_server: str = os.getenv('CUSTOM_SMTP_SERVER', '')
1516
self.pushplus_token = os.getenv('PUSHPLUS_TOKEN')
1617
self.server_push_key = os.getenv('SERVERPUSHKEY')
1718
self.dingding_webhook = os.getenv('DINGDING_WEBHOOK')
@@ -30,7 +31,7 @@ def send_email(self, title: str, content: str, msg_type: Literal['text', 'html']
3031
body = MIMEText(content, msg_type, 'utf-8')
3132
msg.attach(body)
3233

33-
smtp_server = f'smtp.{self.email_user.split("@")[1]}'
34+
smtp_server = self.smtp_server if self.smtp_server else f'smtp.{self.email_user.split("@")[1]}'
3435
with smtplib.SMTP_SSL(smtp_server, 465) as server:
3536
server.login(self.email_user, self.email_pass)
3637
server.send_message(msg)

0 commit comments

Comments
 (0)