You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Python的smtplib拆分邮件主题与正文?发送邮件仅显示主题求助

问题排查:smtplib发送邮件仅显示主题,正文不展示

问题根源在于邮件内容的格式不符合SMTP协议要求:SMTP规定邮件头(如Subject)和正文之间必须用**两个连续的换行符(\n\n)**分隔,你当前的代码只使用了单个换行,导致正文被邮件客户端识别为主题的一部分,从而无法正常展示。

修正后的代码如下:

for name, email in unpaidMembers.items():
    # 关键:Subject后用\n\n分隔邮件头与正文
    body = "Subject: %s dues unpaid.\n\nDear %s,\nRecords show that you have not paid dues for %s. Please make this payment as soon as possible. Thank you!" % (latesMonth, name, latesMonth)
    sendmailStatus = smtpObj.sendmail(FromEmail, email, body)

额外提醒:你的代码里循环变量是email,但调用sendmail时用了ToEmail,这可能是笔误,建议替换成循环里的email变量,确保邮件能发送到对应收件人。另外变量名latesMonth疑似拼写错误(应为lateMonth或latestMonth),虽然不影响正文显示,但会导致月份信息错误。

内容的提问来源于stack exchange,提问作者I Forte Si Daja

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 13:28:12