用python编写发送邮件脚本
时间: 2024-06-09 13:12:38 浏览: 81
python邮件接收发送【完整脚本】
5星 · 资源好评率100%
当然,我可以帮您编写发送邮件的Python脚本。以下是一个基于SMTP协议实现的邮件发送脚本:
```python
import smtplib
from email.mime.text import MIMEText
from email.header import Header
# 发送者邮箱地址
sender = 'your_email_address'
# 发送者邮箱密码
password = 'your_email_password'
# 接收者邮箱地址
receiver = 'receiver_email_address'
# 邮件主题
subject = '邮件主题'
# 邮件内容
content = '邮件内容'
# 创建一个邮件对象
message = MIMEText(content, 'plain', 'utf-8')
message['From'] = Header(sender, 'utf-8')
message['To'] = Header(receiver, 'utf-8')
message['Subject'] = Header(subject, 'utf-8')
# 发送邮件
smtp_obj = smtplib.SMTP_SSL('smtp.qq.com', 465) # 以QQ邮箱为例
smtp_obj.login(sender, password)
smtp_obj.sendmail(sender, [receiver], message.as_string())
print('邮件发送成功')
```
使用时只需将 `sender`、`password`、`receiver`、`subject`、`content` 替换为实际值,便可成功发送邮件。
阅读全文