Я пытаюсь отправить электронное письмо с python, используя учетную запись gmail, однако я являюсь ошибкой аутентификации. Я проверил адрес электронной почты и пароль, но проблем нет. Я даже включил менее безопасное приложение в 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('monitorweight100@gmail.com','monitor weight')
msg = EmailMessage()
msg['Subject'] = 'confirm weight'
msg['From'] = 'monitorweight100@gmail.com'
msg['To'] = 'helloworld@gmail.com'
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('monitorweight100@gmail.com','helloworld@gmail.com',msg)
smtp.quit()
Traceback (most recent call last):
File "/home/pi/smart-scale/mailtest.py", line 36, in <module>
smtp.sendmail('monitorweight100@gmail.com','helloworld@gmail.com',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', 'monitorweight100@gmail.com')