This skill is used to send emails via the SMTP protocol.
Prerequisites
The user needs to provide:
- SMTP server address (e.g., smtp.163.com, smtp.gmail.com)
- SMTP port (usually 587 or 465)
- Email address
- Authorization code or password
Sending process
1. Plain text email
import smtplib
from email.mime.text import MIMEText
from email.header import Header
msg = MIMEText(邮件内容, 'plain', 'utf-8')
msg['Subject'] = Header('邮件主题', 'utf-8')
msg['From'] = 发件人邮箱
msg['To'] = 收件人邮箱
server = smtplib.SMTP_SSL(smtp服务器, smtp端口)
server.login(邮箱, 授权码)
server.sendmail(发件人, [收件人], msg.as_string())
server.quit()
2. HTML email
msg = MIMEText(HTML内容, 'html', 'utf-8')
# 其他同上
3. Markdown to HTML sending
Convert Markdown to HTML and send:
- Remove heading symbols (# ## ###)
- Convert bold (text) → text
- Convert links text → text (url)
- Preserve line breaks
Common SMTP configurations
| SMTP server | Port | SSL port | |
|---|---|---|---|
| 163 Mail | smtp.163.com | 587 | 465 |
| QQ Mail | smtp.qq.com | 587 | 465 |
| Gmail | smtp.gmail.com | 587 | 465 |
Notes
- 163/QQ Mail requires an authorization code instead of the login password
- Gmail requires enabling "less secure app access" or using an app-specific password
- Ensure the format is correct when sending HTML emails