[Mailman-Users] multiple/dynamic outbound smtp hosts?

Mark Sapiro msapiro at value.net
Sun Sep 24 18:06:03 CEST 2006

Ken MacFerrin wrote:
>I've been trying to modify SMTPDirect.py to do my bidding but my Python
>skills are sorely lacking so any help would be greatly appreciated.  My
>initial attempts have been to try to substitute the "mm_cfg.SMTPHOST"
>variable with "mlist.host_name".

This should work.

>Obviously being able to implement a
>solution directly in the mm_cfg file would be preferred but I'm not sure
>that's possible..
>original SMTPDirect code:
>class Connection:
>    def __init__(self):
>        self.__conn = None
>    def __connect(self):
>        self.__conn = smtplib.SMTP()
>        self.__conn.connect(mm_cfg.SMTPHOST, mm_cfg.SMTPPORT)
>        self.__numsessions = mm_cfg.SMTP_MAX_SESSIONS_PER_CONNECTION
>modified code:
>class Connection:
>    def __init__(self):
>        self.__conn = None
>    def __connect(self):
>        self.__conn = smtplib.SMTP()
>        syslog('smtp-failure', 'host = %s, port = %s', mlist.host_name,

What do you get in smtp-failure from this?

>        x = self.__conn.connect(mlist.host_name, mm_cfg.SMTPPORT)

I don't think this is related to your problem, but instead of the
above, do the following:

        if mlist:
            host = mlist.host_name
            host = mm_cfg.SMTPHOST
        x = self.__conn.connect(host, mm_cfg.SMTPPORT)

>        syslog('smtp-failure', 'connect returns: %s', x)

and what do you get from this?

>        self.__conn.local_hostname = 'localhost'

I don't know why you want to do this. Also, if you need to do it, it is
better to give local_hostname='localhost' as an argument to the
smtplib.SMTP() constructor.

>        self.__numsessions = mm_cfg.SMTP_MAX_SESSIONS_PER_CONNECTION
>        self.__set_debuglevel = 1

This does nothing useful. what you want is


and I would put it earlier - right after "self.__conn =
smtplib.SMTP()". Debug messages should go to Mailman's error log.

>Unfortunately, this fails with the following errors in the log:
>Sep 23 20:51:28 2006 (3126) Uncaught runner exception: SMTP instance has
>no attribute 'sock'
>Sep 23 20:51:28 2006 (3126) Traceback (most recent call last):
>  File "/var/lib/mailman/Mailman/Queue/Runner.py", line 111, in _oneloop
>    self._onefile(msg, msgdata)
>  File "/var/lib/mailman/Mailman/Queue/Runner.py", line 167, in _onefile
>    keepqueued = self._dispose(mlist, msg, msgdata)
>  File "/var/lib/mailman/Mailman/Queue/OutgoingRunner.py", line 73, in
>    self._func(mlist, msg, msgdata)
>  File "/var/lib/mailman/Mailman/Handlers/SMTPDirect.py", line 181, in
>    conn.quit()
>  File "/var/lib/mailman/Mailman/Handlers/SMTPDirect.py", line 102, in quit
>    self.__conn.quit()
>  File "smtplib.py", line 716, in quit
>    self.docmd("quit")
>  File "smtplib.py", line 377, in docmd
>    self.putcmd(cmd,args)
>  File "smtplib.py", line 333, in putcmd
>    self.send(str)
>  File "smtplib.py", line 318, in send
>    if self.sock:
>AttributeError: SMTP instance has no attribute 'sock'

I don't see how this specific error can occur. Perhaps the additional
debug information will help.

Mark Sapiro <msapiro at value.net>       The highway is for gamblers,
San Francisco Bay Area, California    better use your sense - B. Dylan

More information about the Mailman-Users mailing list