代码拉取完成,页面将自动刷新
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@Author : y
@License : (C) Copyright 2013-2019, HJIMI
@Contact : bj-yez-magzine@163.com
@File : mail.py
@Time : 2019-07-04 11:09
@Desc :
'''
import os
import sys
from email import encoders
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr
import smtplib
def sendmail(to, subject, content):
try:
smtp_username = os.getenv('smtp_username')
smtp_password = os.getenv('smtp_password')
smtp_server = os.getenv('smtp_server')
msg = MIMEText(content, 'plain', 'utf-8')
msg['From'] = _format_addr(u'运维 <%s>' % smtp_username)
msg['To'] = to
msg['Subject'] = Header(subject, 'utf-8').encode()
server = smtplib.SMTP(smtp_server, 25)
# server.set_debuglevel(1)
server.login(smtp_username, smtp_password)
try:
server.sendmail(smtp_username, to.split(','), msg.as_string())
finally:
server.quit()
except Exception:
print('发送邮件出错')
def _format_addr(s):
name, addr = parseaddr(s)
return formataddr((Header(name, 'utf-8').encode(),addr), 'utf-8')
if __name__=='__main__':
to = os.getenv('mail_to')
subject = os.getenv('mail_subject')
print('sending...')
sendmail(to, subject, 'what''s this !')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。