python发邮件outlook
时间: 2023-08-21 07:15:32 浏览: 55
你可以使用 Python 的 smtplib 模块来发送邮件到 Outlook。以下是一个示例代码,演示如何使用 Outlook SMTP服务器发送邮件:
```pythonimport smtplibfrom email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipart# 发件人信息sender_email = 'your_email@example.com'
sender_password = 'your_password'
# 收件人信息receiver_email = 'recipient@example.com'
# 创建邮件内容message = MIMEMultipart()
message['From'] = sender_emailmessage['To'] = receiver_emailmessage['Subject'] = 'Python 发送邮件示例'
# 添加正文message.attach(MIMEText('这是一封通过 Python 发送的邮件。', 'plain'))
# 登录到 SMTP服务器并发送邮件with smtplib.SMTP('smtp.office365.com',587) as server:
server.starttls()
server.login(sender_email, sender_password)
server.send_message(message)
print('邮件已发送')
```
在上述代码中,你需要将 `your_email@example.com` 和 `your_password` 替换为你的 Outlook 邮箱地址和密码,`recipient@example.com` 替换为收件人的邮箱地址。这段代码将发送一封包含简单文本内容的邮件。
请确保你已经启用了 Outlook 邮箱的 SMTP服务,并且已经安装了必要的依赖模块(smtplib、email)。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://img-home.csdnimg.cn/images/20210720083646.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_column_c1.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_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)