Python error 535, Incorrect Authentication date for sending email (Solved)

Asked

Viewed 121 times

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?

  • 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.

  • 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

  • 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

  • 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.

  • 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.

  • Try to use smtplib.SMTP_SSL() in place of smtplib.SMTP().

Show 3 more comments

1 answer

1

Good afternoon, the problem has been solved. I activated the place that hosts my application, I was not informed what arrangements they took, or what was done, but the e-mail sent back to the norm. I thank Imonferrari for his patience and help and just not to leave it empty, in trying to use smtplib.SMTP_SLL() the error went back to 535, 'Incorrect Authentication data'. I guess that means it was a firewall or other configuration that was applied outside of the code.

  • I’m glad you solved it! Hug!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.