views:

707

answers:

2

Hey I have a windows server running python CGI scripts and I'm having a little trouble with smtplib. The server is running python 2.1 (unfortunately and I can not upgrade it). Anyway I have the following code:

    session = smtplib.SMTP("smtp-auth.ourhosting.com", 587)
    session.login(smtpuser, smtppass)

and it's giving me this error:

exceptions.AttributeError :  SMTP instance has no attribute 'login' :  

I'm assuming this is because the login() method was added after python 2.1. so how do I fix this?

I have to either add the module by uploading the files to the same directory as the cgi script (though I believe smtplib is written in C and needs to be compiled which we can't do on this server)

OR

Do it whatever way is expected by the libsmtp in python 2.1

Thanks so much!

A: 

Do it whatever way is expected by the libsmtp in python 2.1

Aaron Maenpaa
+4  A: 

login() was introduced in Python 2.2, unluckily for you! The only way to do it in Python 2.1's own smtplib would be to issue the AUTH commands manually, which wouldn't be much fun.

I haven't tested it fully but it seems Python 2.2's smtplib should more or less work on 2.1 if you copy it across as you describe (perhaps call it smtplib2.py). It's only a Python module, no C compilation should be necessary. However you will at least need to copy the hmac.py library it relies on from 2.2's lib as well. If you use a later Python version to steal from it starts requiring the email package too which might be more work.

bobince