Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
发送带有python smtp错误535,b'的电子邮件;5.7.3认证不成功';_Python_Email_Smtp_Smtp Auth - Fatal编程技术网

发送带有python smtp错误535,b'的电子邮件;5.7.3认证不成功';

发送带有python smtp错误535,b'的电子邮件;5.7.3认证不成功';,python,email,smtp,smtp-auth,Python,Email,Smtp,Smtp Auth,我尝试使用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(

我尝试使用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()
它返回一个奇怪的错误,我找不到关于(235503)和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')

修复这段代码需要做些什么?

我在Gmail上遇到了这个问题,使用了类似的代码进行测试,这完全不是一个编程错误。谷歌刚刚阻止了来自未知设备的访问。

第二天,我面临着同样的身份验证问题。在第一天,当我编写代码时,它发送邮件的效果非常好。但我的company.com密码已经过期,我不得不重新设置它,但在重新设置后,它也没有停止给出错误。经过两个小时的来回,它现在又能发送邮件了。我改变了一件事,那就是我手工编写了发送者和接收者的电子邮件ID,而不是复制粘贴。其余的都一样。另外,由于我有一个由它组成的函数,所以在使用输入“smail”进行调用之前,我尝试了刷新函数。还应确保手动输入smail输入。请尝试并提出对你有用的建议


def mailfile(smail):
    #smail='receiver@ymail.com'
    import smtplib
    from email.mime.multipart import MIMEMultipart
    from email.mime.text import MIMEText
    from email.mime.base import MIMEBase
    from email import encoders
    fromaddr = "sender@company.com"
    toaddr = smail
    # instance of MIMEMultipart
    msg = MIMEMultipart()
    # storing the senders email address
    msg['From'] = fromaddr
    # storing the receivers email address
    msg['To'] = toaddr
    #storing the subject
    msg['Subject'] = "TEST MAIL"
    #string to store the body of the mail
    body = "Hi DID YOU GET MAIL???"
    #attach the body with the msg instance 
    msg.attach(MIMEText(body, 'plain')) 
    #open the file to be sent
    # PATH WHERE FILE IS BEING STORED
    filename = "filename_with_extension"
    attachment = open("Abra/ka/dabra/file_with_extension", "rb")
    #instance of MIMEBase and named as p
    p = MIMEBase('application', 'octet-stream')
    #To change the payload into encoded form 
    p.set_payload((attachment).read())
    #encode into base64
    encoders.encode_base64(p)
    p.add_header('Content-Disposition', "attachment; filename= %s" % filename)
    #attach the instance 'p' to instance 'msg'
    msg.attach(p)
    #creates SMTP session
    s = smtplib.SMTP('smtp.office365.com',587)
    #start TLS for security
    s.starttls()
    s.ehlo()
    #Authentication
    s.login(fromaddr,'senders_passwd')
    #Converts the Multipart msg into a string
    text = msg.as_string()
    #sending the mail
    s.sendmail(fromaddr, toaddr, text)
    #terminating the session
    s.quit()

您确定需要密码才能发送电子邮件吗?您是否尝试过不使用
登录
部分?如果您的意思是不使用登录方法,那么是的,我将修改问题是否包含密码或登录反斜杠?无反斜杠)