Commit ec3c9cbc authored by Arnaud Fontaine's avatar Arnaud Fontaine

MailHost: Set SMTP socket timeout to 16s (#20161019-4A3BD2).

With old versions of Zope, it was possible to define the SMTP connection
timeout but this is not possible anymore even though MailHost, in turn
using zope.sendmail, uses Python smtplib library.

This meant that once connect() was called, it may have taken around 2
minutes or more before timeout (and this is OS-specific as well)
blocking one Zope thread.
parent 0becf2f2
...@@ -29,3 +29,17 @@ for f in MailBase.__dict__.itervalues(): ...@@ -29,3 +29,17 @@ for f in MailBase.__dict__.itervalues():
except ValueError: except ValueError:
continue continue
f.func_defaults = defaults[:i] + (True,) + defaults[i+1 or len(args):] f.func_defaults = defaults[:i] + (True,) + defaults[i+1 or len(args):]
from App.special_dtml import DTMLFile
MailBase.manage = MailBase.manage_main = DTMLFile('dtml/manageMailHost', globals())
MailBase.smtp_socket_timeout = 16.
from functools import partial
MailBase__makeMailer = MailBase._makeMailer
def _makeMailer(self):
""" Create a SMTPMailer """
smtp_mailer = MailBase__makeMailer(self)
smtp_mailer.SMTP = partial(smtp_mailer.smtp, timeout=self.smtp_socket_timeout)
return smtp_mailer
MailBase._makeMailer = _makeMailer
<dtml-var manage_page_header>
<dtml-var manage_tabs>
<form action="manage_makeChanges" method="post">
<table cellspacing="0" cellpadding="2" border="0">
<tr>
<td align="left" valign="top">
<div class="form-label">
Id
</div>
</td>
<td align="left" valign="top">
<div class="form-text">
&dtml-id;
</div>
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-optional">
Title
</div>
</td>
<td align="left" valign="top">
<input type="text" name="title" size="40"
value="&dtml-title;"/>
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
SMTP Host
</div>
</td>
<td align="left" valign="top">
<input type="text" name="smtp_host" size="40"
value="&dtml-smtp_host;"/>
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
SMTP Port
</div>
</td>
<td align="left" valign="top">
<input type="text" name="smtp_port:int" size="4"
value="&dtml-smtp_port;"/>
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Max. timeout
<br/>
</div>
</td>
<td align="left" valign="top">
<input type="text" name="smtp_socket_timeout:float" size="4"
value="&dtml-smtp_socket_timeout;"/>
</td>
<td>
<span class="form-help">(SMTP socket timeout.)</span>
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Username
</div>
</td>
<td align="left" valign="top">
<input type="text" name="smtp_uid" size="15"
value="&dtml.null-smtp_uid;"/>
</td>
<td>
<span class="form-help">(optional for SMTP AUTH)</span>
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Password
</div>
</td>
<td align="left" valign="top">
<input type="password" name="smtp_pwd" size="15"
value="&dtml.null-smtp_pwd;"/>
</td>
<td>
<span class="form-help">(optional for SMTP AUTH)</span>
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Force TLS
</div>
</td>
<td align="left" valign="top">
<input type="checkbox" name="force_tls:boolean" value="1"
<dtml-if "force_tls">checked</dtml-if>
</td>
<td>
<span class="form-help">(enforce the use of an encrypted connection
to the SMTP server. Mail delivery fails if the SMTP server
does not support encryption)
</span>
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Use mail queue
</div>
</td>
<td align="left" valign="top">
<input type="checkbox" name="smtp_queue:boolean" value="1"
<dtml-if "smtp_queue">checked</dtml-if>
</td>
<td>
<span class="form-help">(asynchronous mail delivery if checked)</span>
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Queue directory<br/>
</div>
</td>
<td align="left" valign="top">
<input type="text" name="smtp_queue_directory" size="30"
value="&dtml-smtp_queue_directory;"/>
</td>
<td>
<span class="form-help">(directory on the filesystem where the mails will be spooled. Only used if 'Use mail queue' is checked.)</span>
</td>
</tr>
<tr>
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<div class="form-element">
<input class="form-element" type="submit" name="submit"
value="Save Changes" />
</div>
</td>
</tr>
</table>
<dtml-if smtp_queue>
<br />
<table cellspacing="0" cellpadding="2" border="0">
<tr>
<td align="left" valign="top">
<div class="form-label">
Mails in queue <br/>
</div>
</td>
<td align="left" valign="top">
<span class="form-help"><dtml-var queueLength></span>
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Status of queue processor thread<br/>
</div>
</td>
<td align="left" valign="top">
<div class="form-help">
<dtml-if "queueThreadAlive()">
Running
<br/>
<a href="manage_restartQueueThread?action=stop">Stop queue processor thread</a> (this may take some seconds)
</dtml-if>
<dtml-if "not queueThreadAlive()">
Stopped
<br/>
<a href="manage_restartQueueThread?action=start">Start queue processor thread</a> (this may take some seconds)
</dtml-if>
</div>
</td>
</tr>
</table>
</dtml-if>
</form>
<dtml-var manage_page_footer>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment