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 = "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