0

I have a simple SMTP client in python:

import smtplib
import ssl

if __name__ == "__main__":
    smtp_server = "smtp.server.ip.addr"
    port = 111
    password = "my_password"
    username = "my@email.com"
    context = ssl._create_unverified_context()
    receiver_email = "my_recipient@gmail.com"
    message = "Hi"

    try:
        server = smtplib.SMTP(smtp_server, port)
        server.starttls(context=context)
        server.login(username, password)
        server.sendmail(username, receiver_email, message)
        server.quit()
    except Exception as e:
        print(e)

But I get following error on sendmail function call:

(550, b'5.7.0 Authentication rejected')

As I have read the library, it means one of the recipients is rejected, but I can't understand why; since it's a valid email address which I am currently and actively using.

Zeinab Abbasimazar
  • 9,835
  • 23
  • 82
  • 131
  • you need to enable ssl and also need to see if the email provider allow you to send mail using current library or configuration, if not then change the configuration accordingly. [similiar case](https://stackoverflow.com/questions/17462628/the-server-response-was-5-7-0-must-issue-a-starttls-command-first-i16sm1806350) – sahasrara62 Aug 29 '21 at 12:48
  • Copy/pasting the `if __name__ == '__main__`:` stuff without understanding its purpose just complicates your code. For the time being, just leave it out. – tripleee Aug 29 '21 at 13:20
  • 550 simply means the transaction was unsuccessful. "Authentication rejeoted" is something quite different than what you link to, and happens earlier in the SMTP transaction dialog. – tripleee Aug 29 '21 at 13:23

0 Answers0