python发送邮件时报: Error: need RCPT command
生活随笔
收集整理的這篇文章主要介紹了
python发送邮件时报: Error: need RCPT command
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在一個項目中,執行了一個任務后卻收不到設定的郵件,經過異常捕獲發現,在發送郵件時報了如下錯誤:
smtplib.SMTPDataError: (503, b'Error: need RCPT command')復現異常
>>> cc_email = ['None'] >>> send_email(subject=subject, content=content, domain=domain, to_email=to_email, cc_email=cc_email) Traceback (most recent call last):File "<console>", line 1, in <module>File "/data/web/scripts/py/custom_send_email.py", line 43, in send_emailmsg.send()File "/usr/local/lib/python3.7/site-packages/django/core/mail/message.py", line 294, in sendreturn self.get_connection(fail_silently).send_messages([self])File "/usr/local/lib/python3.7/site-packages/django/core/mail/backends/smtp.py", line 110, in send_messagessent = self._send(message)File "/usr/local/lib/python3.7/site-packages/django/core/mail/backends/smtp.py", line 126, in _sendself.connection.sendmail(from_email, recipients, message.as_bytes(linesep='\r\n'))File "/usr/local/lib/python3.7/smtplib.py", line 882, in sendmail(code, resp) = self.data(msg)File "/usr/local/lib/python3.7/smtplib.py", line 560, in dataraise SMTPDataError(code, repl) smtplib.SMTPDataError: (503, b'Error: need RCPT command')后排查代碼,原來是在獲取抄送郵箱時獲取了一個包含"None"的列表。
解決辦法:
將cc_email = ['None'] 修改為 cc_email = None 或者 cc_email = []即可。
轉載于:https://my.oschina.net/u/4153263/blog/3070273
總結
以上是生活随笔為你收集整理的python发送邮件时报: Error: need RCPT command的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: WIN10开机启动深度优化超详细万字以上
- 下一篇: python爬取安居客房屋价格用地图表示