jackfrued / jackfrued/Python-100-Days
Day29 发送带附件邮件的示例代码缺少 email.attach(attachment)
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 187k
- Forks
- 55.8k
- PR merge metrics
- No merged PRs in 30d
Description
在 Day21-30/29.Python发送邮件和短信.md 中,「发送带附件的邮件」一节的示例代码存在一个小问题:
代码虽然创建了 attachment 对象并设置了相关头部信息,但没有调用 email.attach(attachment) 将附件添加到邮件主体中。这会导致实际发送的邮件不包含附件。
问题代码位置:
Python
with open(f'resources/王大锤离职证明.docx', 'rb') as file:
attachment = MIMEText(file.read(), 'base64', 'utf-8')
attachment['content-type'] = 'application/octet-stream'
filename = quote('王大锤离职证明.docx')
attachment['content-disposition'] = f'attachment; filename="{filename}"'
此处缺少 email.attach(attachment)
建议修复:
在 with 代码块结束后(或内部末尾)添加:
Python
email.attach(attachment)
感谢作者和维护团队的辛勤付出,这个项目帮助了很多初学者!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open Day21-30/29.Python发送邮件和短信.md and find the “发送带附件的邮件” example. Read the attachment-building block, then ensure the example attaches the created attachment to the email message. Done means the documented example includes the attachment and accurately sends it with the message.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 92/100