【发布时间】:2018-01-07 03:26:56
【问题描述】:
我尝试使用 python smtp 库发送电子邮件:
import smtplib
to ="reciever@mail.adress.com"
user="sender@mail.adress.com"
password="password"
smtpserver = smtplib.SMTP("Outlook.mail.adress.com")
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo()
smtpserver.login(user,password)
header='To:'+to+'\n'+'From:'+user+'\n'+'Subject:test \n'
print (header)
msg = header+'\n test message \n'
smtpserver.sendmail(user,to,msg)
print ('done!')
smtpserver.quit()
它返回奇怪的错误,我找不到太多关于 (235, 503) 和 535 的信息
SMTPAuthenticationError...
...
---> 13 smtpserver.login(user,password)
...
728 # We could not login successfully. Return result of last attempt.
--> 729 raise last_exception
C:\ProgramData\Anaconda3\lib\smtplib.py in login(self, user, password, initial_response_ok)
718 (code, resp) = self.auth(
719 authmethod, getattr(self, method_name),
--> 720 initial_response_ok=initial_response_ok)
721 # 235 == 'Authentication successful'
722 # 503 == 'Error: already authenticated'
C:\ProgramData\Anaconda3\lib\smtplib.py in auth(self, mechanism, authobject, initial_response_ok)
639 if code in (235, 503):
640 return (code, resp)
--> 641 raise SMTPAuthenticationError(code, resp)
642
643 def auth_cram_md5(self, challenge=None):
SMTPAuthenticationError: (535, b'5.7.3 Authentication unsuccessful')
如果我尝试在没有登录方法的情况下执行此操作,我会收到此错误:
---> 20 smtpserver.sendmail(user,to,msg)
--> 866 raise SMTPSenderRefused(code, resp, from_addr)
SMTPSenderRefused: (530, b'5.7.1 Client was not authenticated', 'xxx@mail.adress.com')
修复此代码需要做什么?
【问题讨论】:
-
您确定需要密码才能发送电子邮件吗?你试过没有
login部分吗? -
如果你的意思是没有登录方法,那么是的,我会修改问题
-
里面有密码或登录反斜杠吗?
-
无反斜杠)
标签: python email smtp smtp-auth