SMTP authentication

Meursault pehlenREMOVETHIS at usa.net
Wed Aug 16 06:58:01 EDT 2000


>On Tue, Aug 15, 2000 at 01:15:06AM -0400, Meursault wrote:
>
>> Can someone give me some advice on how to do SMTP authentication with
>> smtplib.py? 
>
>> The server lists extensions of 'PIPELINING', '8BITMIME' and
>> 'AUTH=LOGIN' at connection.  An SMTP library command of
>> server.docmd('auth', 'login') will make the server prompt for a
>> username in Base64 (reply: '334 VXNlcm5hbWU6\015\012'), but I have no
>> idea how to consummate the authentication. Any suggestions?
>
>That has less to do with smtplib.py and more with the RFC on SMTP
>authentication. You can de-code the base64 reply using the (suprise!) base64
>module, encode your response and send it with another docmd or putcmd. If
>you have the time and think it could be useful, I'm pretty sure a patch to
>add support for SMTP auth to the smtplib module would be accepted :-) If I
>had the time to read the SMTP auth RFC I would add it myself, but I won't
>have that time anytime soon.

Thanks for the advice. I don't think I'm quite at the level to be
writing patches for the Python distribution, but your pointing me to
the base64 mod has certainly been helpful. Only problem now is I'm
getting a response of '501 Invalid AUTH reponse' after I send the
password, and I'm not sure why. There seem to be LFs tacked on to the
end of my login info, and I'm wondering if that is the problem. Any
other insights would be appreciated. Here is the output, and my code
follows.

OUTPUT:

send: 'auth login\015\012'
reply: '334 VXNlcm5hbWU6\015\012'		<-- 'Username:'
reply: retcode (334); Msg: VXNlcm5hbWU6
send: '[xxxxxxxxx]\012 \015\012'		<-- (my username)
reply: '334 UGFzc3dvcmQ6\015\012'
reply: retcode (334); Msg: UGFzc3dvcmQ6	<-- 'Password:'
send: '[xxxxxxxx]\012 \015\012'		<-- (my password)'
reply: '501 Invalid AUTH response\015\012'
reply: retcode (501); Msg: Invalid AUTH response
send: 'ehlo d83b2838.dsl.flashcom.net\015\012'
reply: '502 unimplemented (#5.5.1)\015\012'
reply: retcode (502); Msg: unimplemented (#5.5.1)
send: 'helo d83b2838.dsl.flashcom.net\015\012'
reply: '502 unimplemented (#5.5.1)\015\012'
reply: retcode (502); Msg: unimplemented (#5.5.1)


PYTHON CODE:

    import rfc822, string, sys  
    import smtplib, base64
    recipient = "ehlen at flashcom.net"
    username = base64.encodestring('[my username]')
    password = base64.encodestring('[my passsword]')
    SMTPServer = "smtp.flashcom.net"
    fromaddr = "ehlen at flashcom.com"
    toaddrs = recipient
    msg = "This is a test"     
    server = smtplib.SMTP(SMTPServer)
    server.set_debuglevel(1)
    server.docmd('auth', 'login')
    server.docmd(username)
    server.docmd(password)
    server.sendmail(fromaddr, toaddrs, msg)
    server.quit()
    print "Done."




More information about the Python-list mailing list