problem with a python script

Martin Franklin martin.franklin at westgeo.com
Tue Nov 20 11:48:27 EST 2001


gbreed at cix.compulink.co.uk wrote:

> Felix Seeger wrote:
> 
>> Here is the part of the code:
>> 
>> 
>> class Mail:
>>         def __init__(self,outserver="localhost"):
>>                 import smtplib
>>                 self.outserver=outserver
>> 
>>         def sendmail(self,from,to,msg,mopts="",rcptopts=""):
>>                 s=smtplib.SMTP(outserver)
>>                 s.sendmail(from,to,msg,mopts,recptopts)
>>                 s.quit()
> 
> It must have been written for an old interpreter where "from" wasn't a
> keyword.  Try changing the sendmail method to
> 
>          def sendmail(self,fromadddr,to,msg,mopts="",rcptopts=""):
>                  s=smtplib.SMTP(outserver)
>                  s.sendmail(fromaddr,to,msg,mopts,recptopts)
>                  s.quit()
> 
> 

You may also want to change other things

# do the import at top of module so smtplib 'global'
import smtplib

class Mail:
        def __init__(self, outserver="localhost"):
                self.outserver=outserver

# from is keyword so using fromaddr instead
        def sendmail(self, fromaddr, to, msg, mopts="", rcptopts=""):

# outserver would be local to this function/method
# if it existed, so need to use self.outserver
                s=smtplib.SMTP(self.outserver)

# again from is keyword so remember from addr here too.
                s.sendmail(fromaddr, to, msg, mopts, recptopts)
                s.quit()

Martin












More information about the Python-list mailing list