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

Puneet Nebhani picture Puneet Nebhani · Jul 27, 2016 · Viewed 35.6k times · Source

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').

Kindly advise.

Thanks,

Answer

Puneet Nebhani picture Puneet Nebhani · Aug 12, 2016

Actually, when I tried executing the same statements on python console, I came to know that the password was incorrect and it was due to different character encoding.

For all other users, refrain yourself from copy paste

two muppets