This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2008年09月21日 08:11 by shidot, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| sendmail_test.py | shidot, 2008年09月21日 08:11 | |||
| smtplib.diff | ajaksu2, 2009年04月22日 14:40 | Quick and dirty workaround | ||
| smtpbug.py | ajaksu2, 2009年04月25日 22:32 | Example script | ||
| Messages (5) | |||
|---|---|---|---|
| msg73504 - (view) | Author: Takafumi SHIDO (shidot) | Date: 2008年09月21日 08:11 | |
when a SMTP object tries to send a mail through TLS, the smtp server replies retcode 502. When a test code (sendmail_test.py) is executed on Python 3, it stacks on sending mail while the test code works on Python 2.5. Following is the result of the test. The first half is the result on Python 2.5. A mail has been sent without any problem. The second half is the result on Python 3. Upto AUTH, it works fine. But when it sends mail, the server replies retcode 502. This is the message of failure: send: 'mail FROM:<lambda.let@gmail.com> size=176\r\n' reply: b'502 5.5.1 Unrecognized command. u8sm8612791tia.6\r\n' ====================== RESULT ============================ Z:\doc\monthly08円-09\py_book3\script\net>python mail2.py send: 'ehlo [192.168.1.8]\r\n' reply: '250-mx.google.com at your service, [124.41.68.137]\r\n' reply: '250-SIZE 35651584\r\n' reply: '250-8BITMIME\r\n' reply: '250-STARTTLS\r\n' reply: '250 ENHANCEDSTATUSCODES\r\n' reply: retcode (250); Msg: mx.google.com at your service, [124.41.68.137] SIZE 35651584 8BITMIME STARTTLS ENHANCEDSTATUSCODES send: 'STARTTLS\r\n' reply: '220 2.0.0 Ready to start TLS\r\n' reply: retcode (220); Msg: 2.0.0 Ready to start TLS send: 'ehlo [192.168.1.8]\r\n' reply: '250-mx.google.com at your service, [124.41.68.137]\r\n' reply: '250-SIZE 35651584\r\n' reply: '250-8BITMIME\r\n' reply: '250-AUTH LOGIN PLAIN\r\n' reply: '250 ENHANCEDSTATUSCODES\r\n' reply: retcode (250); Msg: mx.google.com at your service, [124.41.68.137] SIZE 35651584 8BITMIME AUTH LOGIN PLAIN ENHANCEDSTATUSCODES send: 'AUTH PLAIN AGxhbWJkYS5sZXRAZ21haWwuY29tAGNoaWtha29zMDA=\r\n' reply: '235 2.7.0 Accepted\r\n' reply: retcode (235); Msg: 2.7.0 Accepted send: 'mail FROM:<lambda.let@gmail.com> size=176\r\n' reply: '250 2.1.0 OK\r\n' reply: retcode (250); Msg: 2.1.0 OK send: 'rcpt TO:<takafumi@shido.info>\r\n' reply: '250 2.1.5 OK\r\n' reply: retcode (250); Msg: 2.1.5 OK send: 'data\r\n' reply: '354 Go ahead\r\n' reply: retcode (354); Msg: Go ahead data: (354, 'Go ahead') send: 'MIME-Version: 1.0\r\nContent-Type: text/plain; charset="us-ascii"\r\nCon ent-Transfer-Encoding: 7bit\r\nFrom: lambda.let@gmail.com\r\nTo: takafumi@shido info\r\nSubject: test\r\n\r\nThis is a test.\r\n.\r\n' reply: '250 2.0.0 OK 1221982163 22sm8756554tim.10\r\n' reply: retcode (250); Msg: 2.0.0 OK 1221982163 22sm8756554tim.10 data: (250, '2.0.0 OK 1221982163 22sm8756554tim.10') send: 'quit\r\n' reply: '221 2.0.0 mx.google.com closing connection 22sm8756554tim.10\r\n' reply: retcode (221); Msg: 2.0.0 mx.google.com closing connection 22sm8756554ti .10 Z:\doc\monthly08円-09\py_book3\script\net>py3 mail2.py Z:\doc\monthly08円-09\py_book3\script\net>c:\python30\python.exe mail2.py send: 'ehlo [192.168.1.8]\r\n' reply: b'250-mx.google.com at your service, [124.41.68.137]\r\n' reply: b'250-SIZE 35651584\r\n' reply: b'250-8BITMIME\r\n' reply: b'250-STARTTLS\r\n' reply: b'250 ENHANCEDSTATUSCODES\r\n' reply: retcode (250); Msg: b'mx.google.com at your service, [124.41.68.137]\nSI E 35651584\n8BITMIME\nSTARTTLS\nENHANCEDSTATUSCODES' send: 'STARTTLS\r\n' reply: b'220 2.0.0 Ready to start TLS\r\n' reply: retcode (220); Msg: b'2.0.0 Ready to start TLS' send: 'ehlo [192.168.1.8]\r\n' reply: b'250-mx.google.com at your service, [124.41.68.137]\r\n' reply: b'250-SIZE 35651584\r\n' reply: b'250-8BITMIME\r\n' reply: b'250-AUTH LOGIN PLAIN\r\n' reply: b'250 ENHANCEDSTATUSCODES\r\n' reply: retcode (250); Msg: b'mx.google.com at your service, [124.41.68.137]\nSI E 35651584\n8BITMIME\nAUTH LOGIN PLAIN\nENHANCEDSTATUSCODES' send: 'AUTH PLAIN AGxhbWJkYS5sZXRAZ21haWwuY29tAGNoaWtha29zMDA=\n\r\n' reply: b'235 2.7.0 Accepted\r\n' reply: retcode (235); Msg: b'2.7.0 Accepted' send: 'mail FROM:<lambda.let@gmail.com> size=176\r\n' reply: b'502 5.5.1 Unrecognized command. u8sm8612791tia.6\r\n' reply: retcode (502); Msg: b'5.5.1 Unrecognized command. u8sm8612791tia.6' send: 'rset\r\n' reply: b'250 2.1.0 OK\r\n' reply: retcode (250); Msg: b'2.1.0 OK' Traceback (most recent call last): File "sendmail_test.py", line 43, in <module> File "sendmail_test.py", line 35, in send_mail File "c:\python30\lib\smtplib.py", line 701, in sendmail raise SMTPSenderRefused(code, resp, from_addr) smtplib.SMTPSenderRefused: (502, b'5.5.1 Unrecognized command. u8sm8612791tia.6 , 'lambda.let@gmail.com') Z:\doc\monthly08円-09\py_book3\script\net> ==================== Test Code (sendmail_test.py) ============= #! python ''' send mail using Python 2.5 and 3''' import smtplib from email.mime.text import MIMEText from email.header import Header def make_mime_text(mail_from, mail_to, subject, body): '''create MIMEText''' msg = MIMEText(body, 'plain', 'ascii') msg['From'] = Header(mail_from, 'ascii') msg['To'] = Header(mail_to, 'ascii') msg['Subject'] = Header(subject, 'ascii') return msg def send_mail(server, mail_from, mail_to, msg, use_tls=False, user='', passwd='', ): '''sendmail, if use_tls=True, use TLS''' sender = smtplib.SMTP(server, (587 if use_tls else 25)) sender.set_debuglevel(1) if use_tls: sender.ehlo() sender.starttls() sender.ehlo() sender.login(user, passwd) sender.sendmail(mail_from, mail_to, msg.as_string()) sender.quit() if __name__ =='__main__': ME = 'lambda.let@gmail.com' TK = 'takafumi@shido.info' send_mail('smtp.gmail.com', ME, (TK,), \ make_mime_text(ME, TK, "test", "This is a test."), True, ME, '********') |
|||
| msg82339 - (view) | Author: Musashi Tamura (miwa) | Date: 2009年02月17日 14:30 | |
The difference is this line. (2.5, work) send: 'AUTH PLAIN AGxhbWJkYS5sZXRAZ21haWwuY29tAGNoaWtha29zMDA=\r\n' (Python3, error) send: 'AUTH PLAIN AGxhbWJkYS5sZXRAZ21haWwuY29tAGNoaWtha29zMDA=\n\r\n' |
|||
| msg86296 - (view) | Author: Daniel Diniz (ajaksu2) * (Python triager) | Date: 2009年04月22日 14:40 | |
The attached patch makes using smtplib in py3k possible. It isn't proposed as a correct fix. |
|||
| msg86560 - (view) | Author: Daniel Diniz (ajaksu2) * (Python triager) | Date: 2009年04月25日 22:32 | |
As pointed by Mariano on IRC, this is closely related to #5259 and #5304. |
|||
| msg86561 - (view) | Author: Daniel Diniz (ajaksu2) * (Python triager) | Date: 2009年04月25日 22:44 | |
Actually, this is fixed by the patch in issue 5259 (also has test). |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:39 | admin | set | github: 48171 |
| 2009年04月25日 22:44:26 | ajaksu2 | set | status: open -> closed resolution: duplicate superseder: smtplib is broken in Python3 messages: + msg86561 |
| 2009年04月25日 22:32:33 | ajaksu2 | set | files:
+ smtpbug.py messages: + msg86560 |
| 2009年04月22日 14:40:30 | ajaksu2 | set | files:
+ smtplib.diff priority: high type: behavior keywords: + patch, easy nosy: + ajaksu2 messages: + msg86296 stage: test needed |
| 2009年04月22日 14:40:11 | ajaksu2 | link | issue5259 dependencies |
| 2009年02月17日 14:30:51 | miwa | set | nosy:
+ miwa messages: + msg82339 |
| 2008年09月21日 08:11:47 | shidot | create | |