请为我提供一个自动发邮件的程序
时间: 2023-03-26 08:00:34 浏览: 67
可以使用 Python 编写一个自动发邮件的程序,使用 smtplib 模块来实现邮件发送功能。以下是一个简单的示例代码:
```python
import smtplib
from email.mime.text import MIMEText
def send_email(subject, content, to_addr):
# 邮件内容
msg = MIMEText(content, 'plain', 'utf-8')
msg['Subject'] = subject
msg['From'] = '发件人邮箱地址'
msg['To'] = to_addr
# 发送邮件
smtp_server = 'SMTP服务器地址'
smtp_port = 25
smtp_username = '发件人邮箱地址'
smtp_password = '发件人邮箱密码'
smtp = smtplib.SMTP(smtp_server, smtp_port)
smtp.login(smtp_username, smtp_password)
smtp.sendmail(smtp_username, to_addr, msg.as_string())
smtp.quit()
# 使用示例
send_email('测试邮件', '这是一封测试邮件', '收件人邮箱地址')
```
注意,需要替换代码中的发件人邮箱地址、发件人邮箱密码、SMTP服务器地址、SMTP端口号和收件人邮箱地址等信息。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_lunwen.png)
![-](https://csdnimg.cn/download_wenku/file_type_lunwen.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)