Step 1安装request依赖
Step 2 插入脚本
脚本模板
import smtplib
from email.mime.text import MIMEText
def send_email(sender_email, sender_password, receiver_email, subject, content, smtp_server, smtp_port):
message = MIMEText(content, 'plain', 'utf-8')
message['Subject'] = subject
message['From'] = sender_email
message['To'] = receiver_email
try:
server = smtplib.SMTP_SSL(smtp_server, smtp_port)
server.login(sender_email, sender_password)
server.sendmail(sender_email, receiver_email, message.as_string())
server.quit()
print("邮件发送成功")
except Exception as e:
print(f"邮件发送失败: {e}")
# 替换以下信息为你的实际配置
sender_email = "[email protected]"
sender_password = "your_password"
receiver_email = "[email protected]"
subject = "定时邮件提醒"
content = "这是一封定时发送的邮件。"
smtp_server = "smtp.example.com"
smtp_port = 465
send_email(sender_email, sender_password, receiver_email, subject, content, smtp_server, smtp_port)
修改后
import smtplib
from email.mime.text import MIMEText
def send_email(sender_email, sender_password, receiver_email, subject, content, smtp_server, smtp_port):
message = MIMEText(content, 'plain', 'utf-8')
message['Subject'] = subject
message['From'] = sender_email
message['To'] = receiver_email
try:
server = smtplib.SMTP_SSL(smtp_server, smtp_port)
server.login(sender_email, sender_password)
server.sendmail(sender_email, receiver_email, message.as_string())
server.quit()
print("邮件发送成功")
except Exception as e:
print(f"邮件发送失败: {e}")
# 以下信息已根据你的配置进行修改
sender_email = "[email protected]"
sender_password = "jonxsfzlihfxciig"
receiver_email = "[email protected]"
subject = "提醒:该做事了"
content = "现在是早上7点50分,制定一下今日计划吧"
smtp_server = "smtp.qq.com"
smtp_port = 465
send_email(sender_email, sender_password, receiver_email, subject, content, smtp_server, smtp_port)
丰富格式
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def send_email(sender_email, sender_password, receiver_email, subject, content, smtp_server, smtp_port):
message = MIMEMultipart("alternative")
message['Subject'] = subject
message['From'] = sender_email
message['To'] = receiver_email
# 创建 HTML 格式的邮件内容
html_content = f"""\
<html>
<body>
<p><h1>现在是早上7点50分,制定一下<font color="#ff0000">今日计划</font>吧:</h1></p>
<ul>
<img src="https://10kcos1-1306082059.cos.ap-shanghai.myqcloud.com/pic-1/aedrian-I6PXPhsMfN4-unsplash.jpg"/>
</ul>
</body>
</html>
"""
# 添加 HTML 内容到邮件
part2 = MIMEText(html_content, "html")
message.attach(part2)
try:
server = smtplib.SMTP_SSL(smtp_server, smtp_port)
server.login(sender_email, sender_password)
server.sendmail(sender_email, receiver_email, message.as_string())
server.quit()
print("邮件发送成功")
except Exception as e:
print(f"邮件发送失败: {e}")
# ... (其他代码保持不变)
# 以下信息已根据你的配置进行修改
sender_email = "[email protected]"
sender_password = "jonxsfzlihfxciig"
receiver_email = "[email protected]"
subject = "提醒:该做事了"
content = "现在是早上7点50分,制定一下今日计划吧"
smtp_server = "smtp.qq.com"
smtp_port = 465
send_email(sender_email, sender_password, receiver_email, subject, content, smtp_server, smtp_port)
docker exec -it bc72e5cdc08a pip3 install feedparser
https://weekly.60004000.xyz/rss.xml
https://weekly.tw93.fun/rss.xml
import smtplib
from email.mime.text import MIMEText
import feedparser
def send_email(sender_email, sender_password, receiver_email, subject, content, smtp_server, smtp_port):
# ... (之前的邮件发送代码保持不变)
def get_latest_posts(feed_url):
feed = feedparser.parse(feed_url)
posts = []
for entry in feed.entries[:3]: # 获取最新的三篇文章
posts.append(f" - [{entry.title}]({entry.link})")
return "\n".join(posts)
# ... (其他代码保持不变)
# 获取周记平台 RSS feed 的 URL
feed_url = "https://weekly.60004000.xyz/rss.xml"
# 获取最新的文章列表
latest_posts = get_latest_posts(feed_url)
# 修改邮件内容,包含最新的文章列表
content = f"来看看\n\n最新文章:\n{latest_posts}"
# ... (其他代码保持不变)
# 以下信息已根据你的配置进行修改
sender_email = "[email protected]"
sender_password = "jonxsfzlihfxciig"
receiver_email = "[email protected]"
subject = "提醒:该做事了"
content = "现在是早上7点50分,制定一下今日计划吧"
smtp_server = "smtp.qq.com"
smtp_port = 465
send_email(sender_email, sender_password, receiver_email, subject, content, smtp_server, smtp_port)
# Fetch RSS feed and extract articles
curl -s "https://weekly.tw93.fun/rss.xml" | grep -P '<item>(.*?)</item>' | while read -r item; do
# Extract article title and content
title=$(echo "$item" | grep -P '<title>(.*?)</title>' | sed 's/<title>|<\/title>//g')
content=$(echo "$item" | grep -P '<content>(.*?)</content>' | sed 's/<content>|<\/content>//g')
# Send article as SMTP email
echo -e "Subject: $title\n\n$content" | sendmail -t "[email protected]"
done