python代码实现以下功能:将我的祝福语群发给我的所有亲人
时间: 2024-03-06 16:50:41 浏览: 65
以下是一份Python代码,可以实现将祝福语群发给所有亲人的功能:
```python
import smtplib
from email.mime.text import MIMEText
# 发送者邮箱和密码
sender_email = "your_email@example.com"
sender_password = "your_email_password"
# 收件人邮箱列表
recipient_emails = ["email1@example.com", "email2@example.com", "email3@example.com"]
# 祝福语内容
blessing = "祝福语内容"
# 构建邮件内容
msg = MIMEText(blessing)
msg['Subject'] = '祝福语'
msg['From'] = sender_email
# 连接SMTP服务器并发送邮件
with smtplib.SMTP_SSL('smtp.example.com', 465) as smtp:
smtp.login(sender_email, sender_password)
for recipient_email in recipient_emails:
msg['To'] = recipient_email
smtp.sendmail(sender_email, recipient_email, msg.as_string())
```
需要替换代码中的 `sender_email`、`sender_password`、`recipient_emails` 和 `blessing` 变量为正确的值。此外,还需要根据你所使用的邮件服务商来修改 SMTP 服务器地址和端口号。
阅读全文