加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
smtp_quectel.py 3.27 KB
一键复制 编辑 原始数据 按行查看 历史
supremeys 提交于 2024-06-18 20:34 . edit email url display
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import subprocess, os
path = os.path.dirname(os.path.abspath(__file__))
test_list = ["13866067773@163.com"]
email_list = ["chavis.chen@quectel.com"," pinky.yang@quectel.com"," hayley.wang@quectel.com"," jun.wu@quectel.com"," yironny.he@quectel.com"," eric.ye@quectel.com"," shirly.wang@quectel.com"," aimee.liu@quectel.com"," kawhi.he@quectel.com"," simona.huang@quectel.com"," barry.liu@quectel.com"," anne.qiu@quectel.com"," eliana.wei@quectel.com"," jocelyn.tan@quectel.com"]
def send_email(to_emails, smtp_server, port, username, password, label, url):
subject = "QuecPython 官网更新通知【请勿回复】"
body_text = "QuecPython 官网更新通知【请勿回复】"
body_html = """\
<html>
<head></head>
<body>
<h1>Dear all:</h1>
<p>QuecPython 官网已更新</p>
<p>分支信息: release 分支</p>
<a :href="{}" target="_blank">提交变更: {}</a>
</body>
</html>
""".format(url, url)
msg = MIMEMultipart('alternative')
msg['Subject'] = subject
msg['From'] = username
msg['To'] = ', '.join(to_emails) # 将收件人列表转换为逗号分隔的字符串
# 添加文本内容
part_text = MIMEText(body_text, 'plain')
msg.attach(part_text)
# 添加HTML内容
if body_html:
part_html = MIMEText(body_html, 'html')
msg.attach(part_html)
# 连接SMTP服务器并发送邮件
try:
server = smtplib.SMTP(smtp_server, port)
server.starttls() # 启用安全传输
server.login(username, password)
server.sendmail(username, to_emails, msg.as_string()) # 发送给多个收件人
server.quit()
print("Emails sent successfully to all recipients.")
except Exception as e:
print(f"Error sending emails: {e}")
# 示例使用
# chavis.chen@quectel.com; pinky.yang@quectel.com; hayley.wang@quectel.com; jun.wu@quectel.com; yironny.he@quectel.com; eric.ye@quectel.com; shirly.wang@quectel.com; aimee.liu@quectel.com; kawhi.he@quectel.com; simona.huang@quectel.com; barry.liu@quectel.com; anne.qiu@quectel.com; eliana.wei@quectel.com; jocelyn.tan@quectel.com
to_emails = email_list # 收件人列表
smtp_server = 'smtp.qq.com' # 替换为你的SMTP服务器地址
port = 587 # 或者根据你的邮件服务商使用465
username = '1520483071@qq.com'
password = 'ycqelqfmuryaigjb' # 替换为你的邮箱密码
def get_commit_id():
base_url = 'https://gitee.com/qpy-doc-center/teedoc_with_qpydoc/compare/'
git_rev_parse_command = ['git', 'rev-parse', '--verify', 'HEAD']
last_full_commit_id = subprocess.check_output(git_rev_parse_command, cwd=path, text=True).strip()
last_commit_id = last_full_commit_id[:7]
# subprocess.check_output( ['git', 'pull'], cwd=path, text=True).strip()
rev_full_commit_id = subprocess.check_output(git_rev_parse_command, cwd=path, text=True).strip()
rev_commit_id = rev_full_commit_id[:7]
url = base_url + last_full_commit_id + '...' + rev_full_commit_id
label = '%s...%s' % (last_commit_id, rev_commit_id)
return label, url
if __name__ == '__main__':
label, url = get_commit_id()
send_email(to_emails, smtp_server, port, username, password, label, url)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化