Commit c8a66859 authored by Hanno Schlichting's avatar Hanno Schlichting

Factored out MailHost

parent 4c48339e
......@@ -51,6 +51,7 @@ eggs =
Persistence
Products.BTreeFolder2
Products.ExternalMethod
Products.MailHost
Products.PythonScripts
Products.StandardCacheManagers
Products.ZCTextIndex
......
......@@ -15,6 +15,9 @@ Bugs Fixed
Restructuring
+++++++++++++
- Factored out the `Products.MailHost` package into its own distributions. It
will no longer be included by default in Zope 2.14 but live on as an
independent add-on.
Features Added
++++++++++++++
......
......@@ -101,6 +101,7 @@ setup(name='Zope2',
# BBB optional dependencies to be removed in Zope 2.14
'Products.BTreeFolder2',
'Products.ExternalMethod',
'Products.MailHost',
'Products.MIMETools',
'Products.OFSP',
'Products.PythonScripts',
......
This diff is collapsed.
MailHost
The MailHost product provides support for sending email from
within the Zope environment using MailHost objects.
An optional character set can be specified to automatically encode unicode
input, and perform appropriate RFC 2822 header and body encoding for
the specified character set. Full python email.Message.Message objects
may be sent.
Email can optionally be encoded using Base64, Quoted-Printable
or UUEncode encoding (though automatic body encoding will be applied if a
character set is specified).
MailHost provides integration with the Zope transaction system and optional
support for asynchronous mail delivery. Asynchronous mail delivery is
implemented using a queue and a dedicated thread processing the queue. The
thread is (re)-started automatically when sending an email. The thread can be
startet manually (in case of restart) by calling its
manage_restartQueueThread?action=start method through HTTP. There is
currently no possibility to start the thread at Zope startup time.
Supports TLS/SSL encryption (requires Python compiled with SSL support)
##############################################################################
#
# Copyright (c) 2002 Zope Foundation and Contributors.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
__rcs_id__='$Id$'
__version__='$Revision: 1.18 $'[11:-2]
from MailHost import MailBase, MailHostError
from DocumentTemplate.DT_Util import parse_params,render_blocks
from DocumentTemplate.DT_String import String
class SendMailTag:
'''the send mail tag, used like thus:
<dtml-sendmail mailhost="someMailHostID">
to: person@their.machine.com
from: me@mymachine.net
subject: just called to say...
boy howdy!
</dtml-sendmail>
Text between the sendmail and /sendmail tags is processed
by the MailHost machinery and delivered. There must be at least
one blank line seperating the headers (to/from/etc..) from the body
of the message.
Instead of specifying a MailHost, an smtphost may be specified
ala 'smtphost="mail.mycompany.com" port=25' (port defaults to 25
automatically). Other parameters are
* mailto -- person (or comma-seperated list of persons) to send the
mail to. If not specified, there **must** be a to: header in the
message.
* mailfrom -- person sending the mail (basically who the recipient can
reply to). If not specified, there **must** be a from: header in the
message.
* subject -- optional subject. If not specified, there **must** be a
subject: header in the message.
* encode -- optional encoding. Possible values are: 'base64',
'quoted-printable' and 'uuencode'.
'''
name='sendmail'
blockContinuations=()
encode=None
def __init__(self, blocks):
tname, args, section=blocks[0]
args=parse_params(args, mailhost=None, mailto=None, mailfrom=None,
subject=None, smtphost=None, port='25',
encode=None)
smtphost=None
has_key=args.has_key
if has_key('mailhost'): mailhost=args['mailhost']
elif has_key('smtphost'): mailhost=smtphost=args['smtphost']
elif has_key(''): mailhost=args['mailhost']=args['']
else: raise MailHostError, 'No mailhost was specified in tag'
for key in ('mailto', 'mailfrom', 'subject', 'port'):
if not args.has_key(key):args[key]=''
if has_key('encode') and args['encode'] not in \
('base64', 'quoted-printable', 'uuencode', 'x-uuencode',
'uue', 'x-uue'):
raise MailHostError, (
'An unsupported encoding was specified in tag')
if not smtphost:
self.__name__=self.mailhost=mailhost
self.smtphost=None
else:
self.__name__=self.smtphost=smtphost
self.mailhost=None
self.section=section
self.args=args
self.mailto=args['mailto']
self.mailfrom=args['mailfrom']
self.subject=None or args['subject']
if args['port'] and type(args['port']) is type('s'):
self.port=args['port']=int(args['port'])
elif args['port']=='':
self.port=args['port']=25
else:
self.port=args['port']
if has_key('encode'):
self.encode=args['encode']
else: self.encode=None
def render(self, md):
args=self.args
has_key=args.has_key
if self.mailhost:
mhost=md[self.mailhost]
elif self.smtphost:
mhost=MailBase( smtp_host=self.smtphost, smtp_port=self.port )
mhost.send(render_blocks(self.section.blocks, md),
self.mailto, self.mailfrom,
self.subject, self.encode
)
return ' '
__call__=render
String.commands['sendmail']=SendMailTag
##############################################################################
#
# Copyright (c) 2002 Zope Foundation and Contributors.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
__doc__='''MailHost Product Initialization
$Id$'''
__version__='$Revision: 1.22 $'[11:-2]
import MailHost
import SendMailTag
def initialize(context):
context.registerClass(
MailHost.MailHost,
permission='Add MailHost objects',
constructors=(MailHost.manage_addMailHostForm,
MailHost.manage_addMailHost),
icon='www/MailHost_icon.gif',
)
context.registerHelp()
context.registerHelpTitle('Zope Help')
##############################################################################
#
# Copyright (c) 2002 Zope Foundation and Contributors.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
Decorator(s)
$Id: MailHost.py 78992 2007-08-19 11:58:08Z andreasjung $
"""
def synchronized(lock):
""" Decorator for method synchronization. """
def wrapper(f):
def method(*args, **kw):
lock.acquire()
try:
return f(*args, **kw)
finally:
lock.release()
return method
return wrapper
<dtml-var manage_page_header>
<dtml-var "manage_form_title(this(), _,
form_title='Add MailHost',
help_product='MailHost',
help_topic='Mail-Host_Add.stx'
)">
<p class="form-help">
MailHost object provide a way to send email from Zope code in DTML or
Python Scripts. <em>SMTP host</em> is the name of the mail server machine.
<em>SMTP port</em> is the port on which the mail server is running the
SMTP service.
</p>
<form action="manage_addMailHost" 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">
<input type="text" name="id" size="40" value="MailHost" />
</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" />
</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="localhost" />
</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="25" />
</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=" Add " />
</div>
</td>
</tr>
</table>
</form>
<dtml-var manage_page_footer>
<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">
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>
MailHost: Sends mail through an SMTP server.
MailHosts allow you to send mail via the Simple Mail Transfer
Protocol (SMTP).
This object can be used deliver mail by the <dtml-sendmail> tag
or via the send() and simple_send() methods.
'send(messageText, mto=None, mfrom=None, subject=None, encode=None)'
Sends an email message where the messageText is an rfc822 formatted
message. This allows you complete control over the message headers,
including setting any extra headers such as Cc: and Reply-To:.
The arguments are:
messageText -- The mail message. It can either be a rfc822
formed text with header fields, or just a body without any
header fields. The other arguments given will override the
header fields in the message, if they exist.
mto -- A commaseparated string or list of recipient(s) of the message.
mfrom -- The address of the message sender.
subject -- The subject of the message.
encode -- The rfc822 defined encoding of the message. The
default of 'None' means no encoding is done. Valid values
are 'base64', 'quoted-printable' and 'uuencode'.
'simple_send(self, mto, mfrom, subject, body)'
Sends a message. Only To:, From: and Subject: headers can be set.
Note that simple_send does not process or validate its arguments
in any way.
The arguments are:
mto -- A commaseparated string of recipient(s) of the message.
mfrom -- The address of the message sender.
subject -- The subject of the message.
body -- The body of the message.
MailHost - Add: Create a new MailHost
Description
Create a new MailHost object.
Controls
'ID' -- The id of the MailHost object.
'Title' -- The title of the MailHost.
'SMTP host' -- The domain name or address of the SMTP mail server
to relay mail through.
'SMTP port' -- The port of the SMTP mail server to relay mail
through.
MailHost - Edit: Edit mail host properties
Description
This view allows you edit the MailHost.
Controls
'ID' -- The id of the MailHost.
'Title' -- The title of the MailHost.
'SMTP host' -- The domain name or address of the SMTP mail server
to relay mail through.
'SMTP port' -- The port of the SMTP mail server to relay mail
through.
##############################################################################
#
# Copyright (c) 2002 Zope Foundation and Contributors.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
def manage_addMailHost(id, title='', smtp_host=None,
localhost='localhost', smtp_port=25,
timeout=1.0):
"""
Add a mailhost object to an ObjectManager.
"""
class MailHost:
"""
MailHost objects work as adapters to Simple Mail Transfer Protocol
(SMTP) servers. MailHosts are used by DTML 'sendmail' tags
to find the proper host to deliver mail to.
"""
def send(messageText, mto=None, mfrom=None, subject=None,
encode=None):
"""
Sends an email message where the messageText is an rfc822 formatted
message. This allows you complete control over the message headers,
including setting any extra headers such as Cc: and Reply-To:.
The arguments are:
messageText -- The mail message. It can either be a rfc822
formed text with header fields, or just a body without any
header fields. The other arguments given will override the
header fields in the message, if they exist.
mto -- A commaseparated string or list of recipient(s) of the message.
mfrom -- The address of the message sender.
subject -- The subject of the message.
encode -- The rfc822 defined encoding of the message. The
default of 'None' means no encoding is done. Valid values
are 'base64', 'quoted-printable' and 'uuencode'.
"""
def simple_send(self, mto, mfrom, subject, body):
"""
Sends a message. Only To:, From: and Subject: headers can be set.
Note that simple_send does not process or validate its arguments
in any way.
The arguments are:
mto -- A commaseparated string of recipient(s) of the message.
mfrom -- The address of the message sender.
subject -- The subject of the message.
body -- The body of the message.
"""
##############################################################################
#
# Copyright (c) 2005 Zope Foundation and Contributors.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""MailHost z3 interfaces.
$Id$
"""
from zope.interface import Interface
class IMailHost(Interface):
def send(messageText, mto=None, mfrom=None, subject=None, encode=None,
charset=None, msg_type=None):
"""Send mail.
"""
import zope.deferredimport
zope.deferredimport.deprecatedFrom(
"Import from zope.sendmail instead",
'zope.sendmail.mailer',
'SMTPMailer',
)
##############################################################################
#
# Copyright (c) 2003 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
# This file is needed to make this a package.
This diff is collapsed.
......@@ -17,6 +17,7 @@ nt-svcutils = 2.13.0
Persistence = 2.13.2
Products.BTreeFolder2 = 2.13.0
Products.ExternalMethod = 2.13.0
Products.MailHost = 2.13.0
Products.MIMETools = 2.13.0
Products.OFSP = 2.13.1
Products.PythonScripts = 2.13.0
......
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