Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
658fa08d
Commit
658fa08d
authored
Aug 19, 2007
by
Andreas Jung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ship MailHost with our own TLS/SSL-aware SMTPMailer
parent
08dc5a38
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
1 deletion
+77
-1
lib/python/Products/MailHost/MailHost.py
lib/python/Products/MailHost/MailHost.py
+5
-1
lib/python/Products/MailHost/mailer.py
lib/python/Products/MailHost/mailer.py
+72
-0
No files found.
lib/python/Products/MailHost/MailHost.py
View file @
658fa08d
...
...
@@ -33,7 +33,6 @@ from Globals import Persistent, DTMLFile, InitializeClass
from
DateTime
import
DateTime
from
zope.interface
import
implements
from
zope.sendmail.mailer
import
SMTPMailer
from
zope.sendmail.maildir
import
Maildir
from
zope.sendmail.delivery
import
DirectMailDelivery
,
QueuedMailDelivery
,
\
QueueProcessorThread
...
...
@@ -41,6 +40,11 @@ from zope.sendmail.delivery import DirectMailDelivery, QueuedMailDelivery, \
from
interfaces
import
IMailHost
from
decorator
import
synchronized
# Use our own TLS/SSL-aware mailer since the zope.sendmail does
# not support TLS/SSL in this version (should be replaced with
# the next version)
from
mailer
import
SMTPMailer
queue_threads
=
{}
# maps MailHost path -> queue processor threada
LOG
=
logging
.
getLogger
(
'MailHost'
)
...
...
lib/python/Products/MailHost/mailer.py
0 → 100644
View file @
658fa08d
##############################################################################
#
# Copyright (c) 2003 Zope Corporation 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.
#
##############################################################################
"""
SMTPMailer with TLS/SSL support
(original code taken from zope.sendmail)
$Id: mailer.py 78981 2007-08-19 06:38:48Z andreasjung $
"""
__docformat__
=
'restructuredtext'
import
socket
from
smtplib
import
SMTP
from
zope.interface
import
implements
from
zope.sendmail.interfaces
import
ISMTPMailer
have_ssl
=
hasattr
(
socket
,
'ssl'
)
class
SMTPMailer
(
object
):
implements
(
ISMTPMailer
)
smtp
=
SMTP
def
__init__
(
self
,
hostname
=
'localhost'
,
port
=
25
,
username
=
None
,
password
=
None
,
no_tls
=
False
,
force_tls
=
False
):
self
.
hostname
=
hostname
self
.
port
=
port
self
.
username
=
username
self
.
password
=
password
self
.
force_tls
=
force_tls
self
.
no_tls
=
no_tls
def
send
(
self
,
fromaddr
,
toaddrs
,
message
):
connection
=
self
.
smtp
(
self
.
hostname
,
str
(
self
.
port
))
# send EHLO
code
,
response
=
connection
.
ehlo
()
if
code
<
200
or
code
>
300
:
raise
RuntimeError
(
'Error sending EHLO to the SMTP server '
'(code=%s, response=%s)'
%
(
code
,
response
))
# encryption support
have_tls
=
connection
.
has_extn
(
'starttls'
)
if
not
have_tls
and
self
.
force_tls
:
raise
RuntimeError
(
'TLS is not available but TLS is required'
)
if
have_tls
and
have_ssl
and
not
self
.
no_tls
:
connection
.
starttls
()
connection
.
ehlo
()
if
connection
.
does_esmtp
:
if
self
.
username
is
not
None
and
self
.
password
is
not
None
:
connection
.
login
(
self
.
username
,
self
.
password
)
elif
self
.
username
:
raise
RuntimeError
(
'Mailhost does not support ESMTP but a username '
'is configured'
)
connection
.
sendmail
(
fromaddr
,
toaddrs
,
message
)
connection
.
quit
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment