1

After executing the code below, it displays a message "smtplib.SMTPAuthenticationError: (535, b'5.7.8 Error: authentication failed: UGFzc3dvcmQ6')" login and password are correct, email created especially for testing. What could be the reasons for failed login?

import smtplib

mailFrom = "Test email sends"
mailTo = ["python123321testowy@op.pl"]
mailSubjest = "Test message"
mailBody = '''
email
    test
        test
'''

msg = '''From: {}
Subject: {}

{}
'''.format(mailFrom,mailSubjest,mailBody)

user = "python123321testowy@op.pl"
password = "pwd"
server = smtplib.SMTP_SSL('SMTP.poczta.onet.pl', 465)
server.ehlo()
server.login(user, password)
server.sendmail(user, mailTo, msg)
server.close()

I have tried changing ports, email service providers and host. After launching the program, a test email is to be sent.

server.set_debuglevel(1) output:

send: 'ehlo [192.168.0.19]\r\n'
reply: b'250-smtp.poczta.onet.pl\r\n'
reply: b'250-PIPELINING\r\n'
reply: b'250-SIZE 90000000\r\n'
reply: b'250-ETRN\r\n'
reply: b'250-AUTH PLAIN LOGIN XOAUTH2\r\n'
reply: b'250-AUTH=PLAIN LOGIN XOAUTH2\r\n'
reply: b'250-ENHANCEDSTATUSCODES\r\n'
reply: b'250 8BITMIME\r\n'
reply: retcode (250); Msg: b'smtp.poczta.onet.pl\nPIPELINING\nSIZE 90000000\nETRN\nAUTH PLAIN LOGIN XOAUTH2\nAUTH=PLAIN LOGIN XOAUTH2\nENHANCEDSTATUSCODES\n8BITMIME'
send: 'AUTH PLAIN AHB5dGhvbjEyMzMyMXRlc3Rvd3lAb3AucGwAUXdlcnR5MTIzNDU2Nzg5QEAh\r\n'
reply: b'535 5.7.8 Error: authentication failed: \r\n'
reply: retcode (535); Msg: b'5.7.8 Error: authentication failed:'
send: 'AUTH LOGIN cHl0aG9uMTIzMzIxdGVzdG93eUBvcC5wbA==\r\n'
reply: b'334 UGFzc3dvcmQ6\r\n'
reply: retcode (334); Msg: b'UGFzc3dvcmQ6'
send: 'UXdlcnR5MTIzNDU2Nzg5QEAh\r\n'
reply: b'535 5.7.8 Error: authentication failed: UGFzc3dvcmQ6\r\n'
reply: retcode (535); Msg: b'5.7.8 Error: authentication failed: UGFzc3dvcmQ6'
send: 'quit\r\n'
reply: b'221 2.0.0 Bye\r\n'
reply: retcode (221); Msg: b'2.0.0 Bye'
Luka
  • 45
  • 1
  • 5

2 Answers2

0

Turn on debugging/tracking SMTP session. It frequently provides more hints.
Use set_debuglevel

In case of this particular SMTP server Iremember sporadic periods of rejecting every login attempt for a few hours. It is not frequent but it is not (very) rate AFAIR.

AnFi
  • 10,493
  • 3
  • 23
  • 47
0

The problem was solved using Papercute and localhost server SMTP. Perpercute using only Windows.

Code:

import smtplib

def send_mail_python():
    mailFrom = "python123321testowy@op.pl"
    mailTo = ["ruby_mailTO@op.pl"]
    mailSubjest = "Test message"
    mailBody = '''
    email
        test
            SMTP Python server
    '''

    msg = '''From: {}
    Subject: {}

    {}
    '''.format(mailFrom, mailSubjest, mailBody)

    try:
        server = smtplib.SMTP('127.0.0.1', 25)
        server.sendmail(mailFrom, mailTo, msg)
        server.close()
    except Exception as e:
        print("any error messages to stdout")
        print(e)
        pass

Solution not closing the problem above. It allows you to check the code and perform tests locally.

Luka
  • 45
  • 1
  • 5