在一個項目中,執行了一個任務後卻收不到設定的郵件,通過異常捕獲發現,在發送郵件時報了以下錯誤:python
smtplib.SMTPDataError: (503, b'Error: need RCPT command')
復現異常web
>>> 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_email msg.send() File "/usr/local/lib/python3.7/site-packages/django/core/mail/message.py", line 294, in send return 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_messages sent = self._send(message) File "/usr/local/lib/python3.7/site-packages/django/core/mail/backends/smtp.py", line 126, in _send self.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 data raise SMTPDataError(code, repl) smtplib.SMTPDataError: (503, b'Error: need RCPT command')
後排查代碼,原來是在獲取抄送郵箱時獲取了一個包含"None"的列表。django
解決辦法:bash
將cc_email = ['None'] 修改成 cc_email = None 或者 cc_email = []便可。dom