-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,793 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
############################################################################## | ||
# | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
############################################################################## | ||
# | ||
# 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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
############################################################################## | ||
# | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<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> |
Oops, something went wrong.