/usr/share/pyshared/zope/sendmail/mailer.py is in python-zope.sendmail 3.7.4-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | ##############################################################################
#
# 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.
#
##############################################################################
"""These are classes which abstract different channels an email
message could be sent out by.
$Id: mailer.py 117103 2010-10-01 09:28:29Z mj $
"""
__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:
code, response = connection.helo()
if code < 200 or code >= 300:
raise RuntimeError('Error sending HELO 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:
username, password = self.username, self.password
if isinstance(username, unicode):
username = username.encode('utf-8')
if isinstance(password, unicode):
password = password.encode('utf-8')
connection.login(username, password)
elif self.username:
raise RuntimeError('Mailhost does not support ESMTP but a username '
'is configured')
connection.sendmail(fromaddr, toaddrs, message)
try:
connection.quit()
except socket.sslerror:
#something weird happened while quiting
connection.close()
|