yagmail 发送邮件
时间: 2023-10-24 10:49:12 浏览: 48
您好!对于使用 yagmail 发送邮件,您可以按照以下步骤进行操作:
1. 首先,确保已经安装了 yagmail 库。您可以使用以下命令进行安装:
```
pip install yagmail
```
2. 导入 yagmail 库:
```python
import yagmail
```
3. 创建一个 yagmail 对象,并传入您的邮箱地址和授权码(或密码):
```python
yag = yagmail.SMTP('your_email@example.com', 'your_password_or_auth_code')
```
4. 使用 yagmail 对象发送邮件。您可以使用 `send` 方法来发送邮件,传入收件人的邮箱地址、邮件主题和邮件正文:
```python
yag.send('recipient@example.com', 'Subject', 'Body of the email')
```
5. 如果您需要发送带附件的邮件,可以使用 `send` 方法的 `attachments` 参数,传入附件的文件路径或文件路径列表:
```python
yag.send('recipient@example.com', 'Subject', 'Body of the email', attachments=['/path/to/file1', '/path/to/file2'])
```
请注意,您需要将 `'your_email@example.com'` 替换为您自己的邮箱地址,`'your_password_or_auth_code'` 替换为您的邮箱密码或授权码。
希望这能帮到您!如果您还有其他问题,请随时提问。