pythonsmtplib

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 = 'abc@gmail.com'
    receivers = ['xyz@gmail.com']      

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

    smtpObj = smtplib.SMTP('xyz@gmail.com',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

  • 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