使用python发送电子邮件时如何解决身份验证错误

take88

我正在尝试使用 gmail 帐户使用 python 发送电子邮件,但是我遇到了身份验证错误。我已经验证了电子邮件地址和密码,但没有问题。我什至在 gmail 中启用了安全性较低的应用程序

from email.message import EmailMessage
import os
import smtplib

context = ssl.create_default_context()
with smtplib.SMTP_SSL('smtp.gmail.com',465, context = context) as 
smtp:
    smtp.login('[email protected]','monitor weight')
    msg = EmailMessage()
    msg['Subject'] = 'confirm weight'
    msg['From'] = '[email protected]'
    msg['To'] = '[email protected]'
    msg.set_content('Detected recent activity')
    msg.add_alternative("""\
            <!DOCTYPE html>
            <html>
            <head>
            <link href="https://fonts.googleapis.com/css?           
family=Niramit" rel="stylesheet">
            </head>
            <body style="margin:0;">
                    <h1>Did you recently weigh yourself?</h1>
                    <img src="https://www.google.com/url?sa=i&rct=j&q=&esrc=s&source=images&cd=&ved=2ahUKEwiOrNW1xPfkAhV57OAKHcZoDKAQjRx6BAgBEAQ&url=https%3A%2F%2Fwww.iconfinder.com%2Ficons%2F3776312%2Fcontrol_diet_healthcare_medical_examination_monitor_scale_weight_icon&psig=AOvVaw2j4tjnCN0wRNR_voOfWKMZ&ust=1569898092735783" alt= "monitorweight" width="900" height="300">
                    <p>Dear User</p>
                    <p>We found some weight that was from your wii    
balance board,was it you?</p>
                    <p>Please confirm that it was you by clicking   
on the link below</p>

                    <button><a href="https://www.google.com">Click    
to confirm</button>

            </body>
            </html>
            """,subtype='html')

smtp.connect('smtp.gmail.com',465)    
smtp.ehlo()
smtp.sendmail('[email protected]','[email protected]',msg)
smtp.quit()



Traceback (most recent call last):
  File "/home/pi/smart-scale/mailtest.py", line 36, in <module>
    smtp.sendmail('[email protected]','[email protected]',msg)
  File "/usr/lib/python3.5/smtplib.py", line 862, in sendmail
    raise SMTPSenderRefused(code, resp, from_addr)
smtplib.SMTPSenderRefused: (530, b'5.5.1 Authentication Required.     Learn more at\n5.5.1  https://support.google.com/mail/?p=WantAuthError     h125sm29106842wmf.31 - gsmtp', '[email protected]')
伊什曼

您正在使用[email protected]登录并尝试将From设置为不同的,[email protected]
保持它们相同,问题应该得到解决。
顺便说一句,msg对于smtp.sendmali()就足够了
试试这个..

msg['From'] = '[email protected]'
# other codes...

smtp.semdmail(msg)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

通过具有双向身份验证的gmail帐户中的Java发送电子邮件

Gmail启用两因素身份验证后,发送电子邮件失败

PHPMailer使用SMTP身份验证发送电子邮件,但Gmail仍声称无法验证发件人

无法通过PHPMailer使用Gmail SMTP服务器发送电子邮件,出现错误:在端口587上提交邮件需要SMTP AUTH。如何解决?

通过PHPMailer发送电子邮件时出现身份验证错误

使用Firebase电子邮件链接身份验证时更改电子邮件模板

如何解决使用gmail发送电子邮件的错误?

使用不带SMTP身份验证的PHPMailer发送电子邮件

Keycloak-使用Keycloak的Admin REST API发送电子邮件时,如何选择电子邮件验证模板?

如何使用Python使用Gmail发送电子邮件

REST身份验证注册后Django不发送电子邮件

使用python发送电子邮件时发生超时错误

发送电子邮件结果为“缺少所需的身份验证”

当我尝试使用phpMailer从php发送电子邮件时,如何解决SMTP连接上的错误?POP / IMAP

使用python通过Outlook发送电子邮件时,如何解决连接错误?

Postfix允许未经身份验证的用户发送电子邮件

发送电子邮件时,PEAR邮件身份验证失败

无法使用cram_md5身份验证通过SMTP通过SMTP发送电子邮件

Postfix身份验证失败,无法发送电子邮件

从Tomee发送电子邮件时,如何解决与Classloader相关的“ java.lang.LinkageError”?

使用SMTP发送电子邮件时如何解析换行符

使用MUTT发送电子邮件而无需身份验证

Redmine电子邮件配置-发送邮件时发生错误(530 5.7.0需要身份验证)

如何从python发送电子邮件

如何解决从联系表单发送电子邮件的错误

无法使用 SMTP Gmail 服务器发送电子邮件身份验证

无需身份验证就无法发送电子邮件

上传文件或发送电子邮件时出现身份验证错误

无法在 docker 容器中使用 stmp python 发送电子邮件,如何解决?