'smtplib.SMTPAuthenticationError: (535, '5.7.3 Authentication unsuccessful')

I am trying to use smtplib for sending mails in python 2.7. The below code is pretty simple:

import smtplib

def main(argv=None):

    sender = '[email protected]'
    receivers = ['[email protected]']      

    message = """
    This is a test e-mail message.
    """

    smtpObj = smtplib.SMTP('[email protected]',25)

    smtpObj.login('abc', 'pwd')       
    smtpObj.sendmail(sender, receivers, message)         
    print "Successfully sent email"


if __name__ == '__main__':
    main()

Now when I execute the below code, I keep getting this exception:

smtplib.SMTPAuthenticationError: (535, '5.7.3 Authentication unsuccessful').


Solution 1:[1]

had the same issue.

2 options,

try changing:

smtpObj = smtplib.SMTP('[email protected]',25)

to:

smtpObj = smtplib.SMTP('[email protected]',587)

Other option is that your login is not correct. In my case im using exchange and the login name is not email adres but just username

Here is the code im using for exchange server:

import smtplib

def sendmail():
    subject = 'message subject'
    to = '[email protected]'
    sender = 'bjorn@***.nl'
    smtpserver = smtplib.SMTP("mail.mymailserver.nl",587)
    user = 'myussername'
    password = 'mypassword'
    smtpserver.ehlo()
    smtpserver.starttls()
    smtpserver.ehlo
    smtpserver.login(user, password)
    header = 'To:' + to + '\n' + 'From: ' + sender + '\n' + 'Subject:' + subject + '\n'
    message = header + '\n This is my message'
    smtpserver.sendmail(sender, to, message)
    smtpserver.close()

Solution 2:[2]

This Problem is With Your Gmail if You double checked Your credentials. You Can do following steps to resolve it:

1.Enable IMAP and/or POP3:

 1. Go to the "Settings", e.g. click on the "Gears" icon and select
    "Settings".
 2. Click on "Forwarding and POP/IMAP".
 3. Enable "IMAP Access" and/or "POP Download"
  1. Allow Less Secure Apps to sign in Your Gmail.
 1. Login with your gmail account and find "Allow less secure apps:"
    from [Here][1]
 2. Google manages security with your gmail account. You need to turn on "Allow 
      less secure apps:" and you will receive mail in your gmail account.
      [1]: https://myaccount.google.com/security#activity

Solution 3:[3]

For completeness answering this question, I have encountered exactly the same error multiple times - each time for a different reason. This error message has been haunting me and I kind of mutated into a self-proclaimed expert on this very error message. Here is a list of all the issues I faced with it and how I solved it.

  • Needed to enable "less secure app" in your Google Admin (https://admin.google.com/ac/security/lsa)

  • Even if the above is enabled, the service might fail if you have a two-factor authentication setup in your email. The solution is to create an app specific password (https://myaccount.google.com/u/5/apppasswords) that must be used as the password for smtplib in Python instead.

  • If you do this for the first time with an unknown IP. There may be a secret Captcha priming the authentication. You may see then actually a 534 error code instead of a 535 but I can't guarantee that. You will need to click on a link first to clear the Captcha (https://accounts.google.com/DisplayUnlockCaptcha). You might need to wait 10 min before it actually registers it. So grab a coffee.

  • Finally, you will get the same error message, if you have not opened the correct port. I had port 587 not opened in firewalld. I had smtp and smtps as services enabled, but these only cover ports 25 and 465 by default. So, if you use 587, make sure it is open, e.g. for firewalld, sudo firewall-cmd --permanent --add-port=587/tcp and restart your firewalld service.

  • Lastly, this mail still fail if you have not setup your SSL correctly at your server. At some point I had the error message and upon further investigation in some logs I saw it failed to do a handshake.

  • Update lastly: I had the ehlo() accidently at the wrong place in my code that suddently started to throw the 535 Authentication error, that is:

    session = smtplib.SMTP('smtp.gmail.com', 587)

    session.starttls() session.login(sender_address, sender_pass)

    session.ehlo("yourdomain.com") # <-- Make sure this comes after starttls() and not before

Solution 4:[4]

The reason for this problem is that the password should be the client authorization code, not the login password of the mailbox.

Solution 5:[5]

the low security methode was temporary and i couldn't use it in production but I found an article that made it easier using OAuth for authentication to GMail here with an example code and it works perfectly.

Solution 6:[6]

You can also try changing the port from 587 to 25. This worked for me.

Solution 7:[7]

In my personal case it was Outlook that blocked my account for breaking tems of use. I logged in again via browser and it worked allright.

Solution 8:[8]

Here is one of the common and most simple method to make the image get a circular border using card view in android in XML

first create a card view inside your XML and inside that create a image view with exactly 1dp less then the card view in both width and height and then try to adjust the cardCornerRadius as per your requirements, that's it it is as simple as that.

I'm using androidx.cardview.widget.CardView here.

<androidx.cardview.widget.CardView
            android:layout_width="70dp"
            android:layout_height="70dp"
            app:cardCornerRadius="35dp"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true">

            <ImageView
                android:id="@+id/rounded_profile_img"
                android:layout_width="69dp"
                android:layout_height="69dp"
                android:scaleType="centerCrop"/>

        </androidx.cardview.widget.CardView>

Thank you hope y'll like it and it is helpful for everyone.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Devesh
Solution 3
Solution 4 weiliang
Solution 5 bessam Sahli
Solution 6 David J.
Solution 7
Solution 8 Shubham K.