0
Good morning, my application already hosted and running until last week, began to present this error: 535, 'Incorrect Authentication data' at the time the e-mail is requested.
At first glance I would say that it is a problem of login or password but when using the same code on my local machine I get success in sending, I also performed tests on other development machines. I used two different e-mail servers respecting the settings of smtp, tls/ssl and port, again on my machine I get success but in the application already hosted the error is always the same.
The only thing I have located differently was the IP where the application is hosted, is an IP with "location" outside Brazil, I checked if the IP was in a black-list and they are clean. I used a company account in Gmail, a Localweb account and a company account in Office365 with the same results Any guidance help is welcome.
Follows the code used for sending:
def envio(self, para, assunto, corpo):
try:
fromaddr = "[email protected]"
toaddr = para
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = assunto
body = corpo
msg.attach(MIMEText(body, 'html'))
s = smtplib.SMTP('smtp.office365.com', 587)
s.starttls()
s.login(fromaddr, "minha_senha")
text = msg.as_string()
s.sendmail(fromaddr, toaddr, text)
s.quit()
return True
except smtplib.SMTPException as e:
print(e)
return False
John, good morning! Already tried to modify the door of smtp to 465 for example?
– lmonferrari
Imonferrari, because of the doubts I performed the test and latch did not get answer from the smtp server well on line s = smtplib.SMTP('smtp.office365.com', 465) - as you suggested.
– João Douglas
The information was then going. Possibly smtp authentication is disabled. You must authorize the user who will send the emails in the microsoft admin panel. Link
– lmonferrari
Sorry, but I didn’t understand. when sending the command: s = smtplib.SMTP('smtp.office365.com', 587) The user hasn’t even been informed yet. It looks more like 465 is closed. All the way I have access to change microsoft settings but I did not find anything like, could you give me more details ? Thanks
– João Douglas
Possibly it shows that the error is in that line because it is that it contains the wrong door ''.
s.sendmail(fromaddr, toaddr, text)
when you call this line of code you pass the port as parameter as well.'fromaddr
is the email of who is sending the email, you must authorize this email to authenticate. https://admin.microsoft.com/ -> Users -> Active users. You go to the email application part and authorize the user.– lmonferrari
link
– lmonferrari
First of all, thank you so much for your help. I entered the settings as per your instructions but all items were already marked (allowed). With new tests the error has changed to "Connection unexpectedly closed". I can ping smtp, I believe it is not firewall in this case.
– João Douglas
Try to use
smtplib.SMTP_SSL()
in place ofsmtplib.SMTP()
.– lmonferrari