本文整理汇总了Python中repoze.sendmail.delivery.QueuedMailDelivery类的典型用法代码示例。如果您正苦于以下问题:Python QueuedMailDelivery类的具体用法?Python QueuedMailDelivery怎么用?Python QueuedMailDelivery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QueuedMailDelivery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testNonASCIIAddrs
def testNonASCIIAddrs(self):
import os
from email.mime import base
import transaction
from repoze.sendmail.delivery import QueuedMailDelivery
from repoze.sendmail._compat import b
from repoze.sendmail._compat import text_type
delivery = QueuedMailDelivery(self.maildir_path)
non_ascii = b('LaPe\xc3\xb1a').decode('utf-8')
fromaddr = non_ascii+' <[email protected]>'
toaddrs = (non_ascii+' <[email protected]>',)
message = base.MIMEBase('text', 'plain')
message['From'] = fromaddr
message['To'] = ','.join(toaddrs)
delivery.send(fromaddr, toaddrs, message)
self.assertTrue(os.listdir(os.path.join(self.maildir_path, 'tmp')))
self.assertFalse(os.listdir(os.path.join(self.maildir_path, 'new')))
transaction.commit()
self.assertFalse(os.listdir(os.path.join(self.maildir_path, 'tmp')))
self.assertTrue(os.listdir(os.path.join(self.maildir_path, 'new')))
self.qp.send_messages()
self.assertTrue(len(self.qp.mailer.sent_messages), 1)
queued_fromaddr, queued_toaddrs, queued_message = (
self.qp.mailer.sent_messages[0])
self.assertEqual(queued_fromaddr, fromaddr)
self.assertEqual(queued_toaddrs, toaddrs)
示例2: createQueuedDelivery
def createQueuedDelivery():
delivery = QueuedMailDelivery(queuePath)
handler('registerUtility', delivery, IMailDelivery, name)
mailerObject = queryUtility(IMailer, mailer)
if mailerObject is None:
raise ConfigurationError("Mailer %r is not defined" %mailer)
if processorThread:
qp = QueueProcessor()
qp.mailer = mailerObject
qp.queue_path = queuePath
delivery.processor_thread = qp.send_messages_thread()
示例3: testSend
def testSend(self):
from email.message import Message
import transaction
from repoze.sendmail.delivery import QueuedMailDelivery
from repoze.sendmail._compat import text_type
delivery = QueuedMailDelivery('/path/to/mailbox')
fromaddr = '[email protected]'
toaddrs = ('[email protected]',
'[email protected]')
message = Message()
message['From'] = 'Jim <[email protected]>'
message['To'] = 'some-zope-coders:;'
message['Date'] = 'Date: Mon, 19 May 2003 10:17:36 -0400'
message['Message-Id'] = ext_msgid = '<[email protected]>'
message['Subject'] = 'example'
message.set_payload('This is just an example\n')
msgid = delivery.send(fromaddr, toaddrs, message)
self.assertEqual(msgid, '<[email protected]>')
self.assertEqual(MaildirMessageStub.commited_messages, [])
self.assertEqual(MaildirMessageStub.aborted_messages, [])
transaction.commit()
self.assertEqual(len(MaildirMessageStub.commited_messages), 1)
self.assertEqual(MaildirMessageStub.aborted_messages, [])
message = MaildirMessageStub.commited_messages[0]
self.assertEqual(text_type(message['X-Actually-From']), fromaddr)
self.assertEqual(text_type(
message['X-Actually-To']), ','.join(toaddrs))
MaildirMessageStub.commited_messages = []
msgid = delivery.send(fromaddr, toaddrs, message)
self.assertTrue('@' in msgid)
self.assertEqual(MaildirMessageStub.commited_messages, [])
self.assertEqual(MaildirMessageStub.aborted_messages, [])
transaction.commit()
self.assertEqual(len(MaildirMessageStub.commited_messages), 1)
self.assertEqual(MaildirMessageStub.commited_messages[0].get_payload(),
'This is just an example\n')
self.assertEqual(message['Message-Id'], msgid)
self.assertEqual(message['Message-Id'], ext_msgid)
self.assertEqual(MaildirMessageStub.aborted_messages, [])
MaildirMessageStub.commited_messages = []
msgid = delivery.send(fromaddr, toaddrs, message)
self.assertEqual(MaildirMessageStub.commited_messages, [])
self.assertEqual(MaildirMessageStub.aborted_messages, [])
transaction.abort()
self.assertEqual(MaildirMessageStub.commited_messages, [])
self.assertEqual(len(MaildirMessageStub.aborted_messages), 1)
示例4: __init__
def __init__(self, settings):
self.mfrom = settings.get("envelope_from_addr", "[email protected]%s" % getfqdn())
self.bounce_from = settings.get("postoffice.bounce_from_email", self.mfrom)
queue_path = settings.get("mail_queue_path", None)
if queue_path is None:
# Default to var/mail_queue
# we assume that the console script lives in the 'bin' dir of a
# sandbox or buildout, and that the mail_queue directory lives in
# the 'var' directory of the sandbox or buildout
exe = sys.executable
sandbox = os.path.dirname(os.path.dirname(os.path.abspath(exe)))
queue_path = os.path.join(os.path.join(sandbox, "var"), "mail_queue")
queue_path = os.path.abspath(os.path.normpath(os.path.expanduser(queue_path)))
QueuedMailDelivery.__init__(self, queue_path)
示例5: __init__
def __init__(self, **kw):
smtp_mailer = kw.pop("smtp_mailer", None)
if smtp_mailer is None:
host = kw.pop("host", "localhost")
port = kw.pop("port", 25)
username = kw.pop("username", None)
password = kw.pop("password", None)
tls = kw.pop("tls", False)
ssl = kw.pop("ssl", False)
keyfile = kw.pop("keyfile", None)
certfile = kw.pop("certfile", None)
debug = kw.pop("debug", 0)
if ssl:
smtp_mailer = SMTP_SSLMailer(
hostname=host,
port=port,
username=username,
password=password,
no_tls=not (tls),
force_tls=tls,
debug_smtp=debug,
keyfile=keyfile,
certfile=certfile,
)
else:
smtp_mailer = SMTPMailer(
hostname=host,
port=port,
username=username,
password=password,
no_tls=not (tls),
force_tls=tls,
debug_smtp=debug,
)
self.smtp_mailer = smtp_mailer
sendmail_mailer = kw.pop("sendmail_mailer", None)
if sendmail_mailer is None:
sendmail_mailer = SendmailMailer(kw.pop("sendmail_app", None), kw.pop("sendmail_template", None))
self.sendmail_mailer = sendmail_mailer
self.queue_path = kw.pop("queue_path", None)
self.default_sender = kw.pop("default_sender", None)
transaction_manager = kw.pop("transaction_manager", None)
if transaction_manager is None:
transaction_manager = transaction.manager
self.transaction_manager = transaction_manager
if kw:
raise ValueError("invalid options: %s" % ", ".join(sorted(kw.keys())))
self.direct_delivery = DirectMailDelivery(self.smtp_mailer, transaction_manager=transaction_manager)
if self.queue_path:
self.queue_delivery = QueuedMailDelivery(self.queue_path, transaction_manager=transaction_manager)
else:
self.queue_delivery = None
self.sendmail_delivery = DirectMailDelivery(self.sendmail_mailer, transaction_manager=transaction_manager)
示例6: __init__
def __init__(self, settings):
self.mfrom = getattr(settings, 'envelope_from_addr', None)
queue_path = getattr(settings, "mail_queue_path", None)
if queue_path is None:
# Default to var/mail_queue
# we assume that the console script lives in the 'bin' dir of a
# sandbox or buildout, and that the mail_queue directory lives in
# the 'var' directory of the sandbox or buildout
exe = sys.executable
sandbox = os.path.dirname(os.path.dirname(os.path.abspath(exe)))
queue_path = os.path.join(
os.path.join(sandbox, "var"), "mail_queue"
)
queue_path = os.path.abspath(os.path.normpath(
os.path.expanduser(queue_path)))
QueuedMailDelivery.__init__(self, queue_path)
示例7: testNonASCIIAddrs
def testNonASCIIAddrs(self):
from email.message import Message
from repoze.sendmail.delivery import QueuedMailDelivery
delivery = QueuedMailDelivery('/path/to/mailbox')
non_ascii = b('LaPe\xc3\xb1a').decode('utf-8')
fromaddr = non_ascii+' <[email protected]>'
toaddrs = (non_ascii+' <[email protected]>',)
message = Message()
delivery.send(fromaddr, toaddrs, message)
transaction.commit()
message = MaildirMessageStub.commited_messages[0]
self.assertEqual(raw_header(message['X-Actually-From']), fromaddr)
self.assertEqual(raw_header(
message['X-Actually-To']), ','.join(toaddrs))
示例8: testSend
def testSend(self):
from repoze.sendmail.delivery import QueuedMailDelivery
delivery = QueuedMailDelivery('/path/to/mailbox')
fromaddr = '[email protected]'
toaddrs = ('[email protected]',
'[email protected]')
zope_headers = ('X-Zope-From: [email protected]\n'
'X-Zope-To: [email protected], [email protected]\n')
opt_headers = ('From: Jim <[email protected]>\n'
'To: some-zope-coders:;\n'
'Date: Mon, 19 May 2003 10:17:36 -0400\n'
'Message-Id: <[email protected]>\n')
message = ('Subject: example\n'
'\n'
'This is just an example\n')
msgid = delivery.send(fromaddr, toaddrs, opt_headers + message)
self.assertEquals(msgid, '[email protected]')
self.assertEquals(MaildirWriterStub.commited_messages, [])
self.assertEquals(MaildirWriterStub.aborted_messages, [])
transaction.commit()
self.assertEquals(MaildirWriterStub.commited_messages,
[zope_headers + opt_headers + message])
self.assertEquals(MaildirWriterStub.aborted_messages, [])
MaildirWriterStub.commited_messages = []
msgid = delivery.send(fromaddr, toaddrs, message)
self.assert_('@' in msgid)
self.assertEquals(MaildirWriterStub.commited_messages, [])
self.assertEquals(MaildirWriterStub.aborted_messages, [])
transaction.commit()
self.assertEquals(len(MaildirWriterStub.commited_messages), 1)
self.assert_(MaildirWriterStub.commited_messages[0].endswith(message))
new_headers = MaildirWriterStub.commited_messages[0][:-len(message)]
self.assert_(new_headers.find('Message-Id: <%s>' % msgid) != -1)
self.assert_(new_headers.find('X-Zope-From: %s' % fromaddr) != 1)
self.assert_(new_headers.find('X-Zope-To: %s' % ", ".join(toaddrs)) != 1)
self.assertEquals(MaildirWriterStub.aborted_messages, [])
MaildirWriterStub.commited_messages = []
msgid = delivery.send(fromaddr, toaddrs, opt_headers + message)
self.assertEquals(MaildirWriterStub.commited_messages, [])
self.assertEquals(MaildirWriterStub.aborted_messages, [])
transaction.abort()
self.assertEquals(MaildirWriterStub.commited_messages, [])
self.assertEquals(len(MaildirWriterStub.aborted_messages), 1)
示例9: test_send
def test_send(self):
import transaction
from repoze.sendmail.delivery import QueuedMailDelivery
from repoze.sendmail._compat import text_type
delivery = QueuedMailDelivery('/path/to/mailbox')
fromaddr = '[email protected]'
toaddrs = ('[email protected]',
'[email protected]')
message = self._makeMessage()
msgid = delivery.send(fromaddr, toaddrs, message)
self.assertEqual(msgid, '<[email protected]>')
self.assertEqual(MaildirMessageStub.commited_messages, [])
self.assertEqual(MaildirMessageStub.aborted_messages, [])
transaction.commit()
self.assertEqual(len(MaildirMessageStub.commited_messages), 1)
self.assertEqual(MaildirMessageStub.aborted_messages, [])
message = MaildirMessageStub.commited_messages[0]
self.assertEqual(text_type(message['X-Actually-From']), fromaddr)
self.assertEqual(text_type(
message['X-Actually-To']), ','.join(toaddrs))
MaildirMessageStub.commited_messages = []
message = self._makeMessage()
msgid = delivery.send(fromaddr, toaddrs, message)
self.assertTrue('@' in msgid)
self.assertEqual(MaildirMessageStub.commited_messages, [])
self.assertEqual(MaildirMessageStub.aborted_messages, [])
transaction.commit()
self.assertEqual(len(MaildirMessageStub.commited_messages), 1)
self.assertEqual(MaildirMessageStub.commited_messages[0].get_payload(),
'This is just an example\n')
self.assertEqual(message['Message-Id'], msgid)
self.assertEqual(message['Message-Id'], '<[email protected]>')
self.assertEqual(MaildirMessageStub.aborted_messages, [])
MaildirMessageStub.commited_messages = []
message = self._makeMessage()
msgid = delivery.send(fromaddr, toaddrs, message)
self.assertEqual(MaildirMessageStub.commited_messages, [])
self.assertEqual(MaildirMessageStub.aborted_messages, [])
transaction.abort()
self.assertEqual(MaildirMessageStub.commited_messages, [])
self.assertEqual(len(MaildirMessageStub.aborted_messages), 1)
示例10: test_send
def test_send(self):
import transaction
from repoze.sendmail.delivery import QueuedMailDelivery
from repoze.sendmail._compat import text_type
delivery = QueuedMailDelivery("/path/to/mailbox")
fromaddr = "[email protected]"
toaddrs = ("[email protected]", "[email protected]")
message = self._makeMessage()
msgid = delivery.send(fromaddr, toaddrs, message)
self.assertEqual(msgid, "<[email protected]>")
self.assertEqual(MaildirMessageStub.commited_messages, [])
self.assertEqual(MaildirMessageStub.aborted_messages, [])
transaction.commit()
self.assertEqual(len(MaildirMessageStub.commited_messages), 1)
self.assertEqual(MaildirMessageStub.aborted_messages, [])
message = MaildirMessageStub.commited_messages[0]
self.assertEqual(text_type(message["X-Actually-From"]), fromaddr)
self.assertEqual(text_type(message["X-Actually-To"]), ",".join(toaddrs))
MaildirMessageStub.commited_messages = []
message = self._makeMessage()
msgid = delivery.send(fromaddr, toaddrs, message)
self.assertTrue("@" in msgid)
self.assertEqual(MaildirMessageStub.commited_messages, [])
self.assertEqual(MaildirMessageStub.aborted_messages, [])
transaction.commit()
self.assertEqual(len(MaildirMessageStub.commited_messages), 1)
self.assertEqual(MaildirMessageStub.commited_messages[0].get_payload(), "This is just an example\n")
self.assertEqual(message["Message-Id"], msgid)
self.assertEqual(message["Message-Id"], "<[email protected]>")
self.assertEqual(MaildirMessageStub.aborted_messages, [])
MaildirMessageStub.commited_messages = []
message = self._makeMessage()
msgid = delivery.send(fromaddr, toaddrs, message)
self.assertEqual(MaildirMessageStub.commited_messages, [])
self.assertEqual(MaildirMessageStub.aborted_messages, [])
transaction.abort()
self.assertEqual(MaildirMessageStub.commited_messages, [])
self.assertEqual(len(MaildirMessageStub.aborted_messages), 1)
示例11: setUp
def setUp(self):
from repoze.sendmail.delivery import QueuedMailDelivery
from repoze.sendmail.maildir import Maildir
self.dir = mkdtemp()
self.queue_dir = os.path.join(self.dir, "queue")
self.delivery = QueuedMailDelivery(self.queue_dir)
self.maildir = Maildir(self.queue_dir, True)
self.mailer = _makeMailerStub()
self.save_stderr = sys.stderr
sys.stderr = self.stderr = StringIO()
示例12: __init__
def __init__(self,
host='localhost',
port=25,
username=None,
password=None,
tls=False,
ssl=False,
keyfile=None,
certfile=None,
queue_path=None,
default_sender=None,
sendmail_app=None,
sendmail_template=None,
debug=0):
if ssl:
self.smtp_mailer = SMTP_SSLMailer(
hostname=host,
port=port,
username=username,
password=password,
no_tls=not(tls),
force_tls=tls,
debug_smtp=debug,
keyfile=keyfile,
certfile=certfile)
else:
self.smtp_mailer = SMTPMailer(
hostname=host,
port=port,
username=username,
password=password,
no_tls=not(tls),
force_tls=tls,
debug_smtp=debug)
self.direct_delivery = DirectMailDelivery(self.smtp_mailer)
if queue_path:
self.queue_delivery = QueuedMailDelivery(queue_path)
else:
self.queue_delivery = None
self.sendmail_mailer = SendmailMailer(sendmail_app, sendmail_template)
self.sendmail_delivery = DirectMailDelivery(self.sendmail_mailer)
self.default_sender = default_sender
示例13: TestConsoleApp
class TestConsoleApp(TestCase):
def setUp(self):
from repoze.sendmail.delivery import QueuedMailDelivery
from repoze.sendmail.maildir import Maildir
self.dir = mkdtemp()
self.queue_dir = os.path.join(self.dir, "queue")
self.delivery = QueuedMailDelivery(self.queue_dir)
self.maildir = Maildir(self.queue_dir, True)
self.mailer = _makeMailerStub()
self.save_stderr = sys.stderr
sys.stderr = self.stderr = StringIO()
def tearDown(self):
sys.stderr = self.save_stderr
shutil.rmtree(self.dir)
def _captureLoggedErrors(self, cmdline):
from repoze.sendmail import queue
logged = []
monkey = _Monkey(queue, _log_error=logged.append)
# py 25 compat, can't use with statement
exc_info = ()
try:
monkey.__enter__()
app = ConsoleApp(cmdline.split())
except: # pragma: no cover
exc_info = sys.exc_info()
monkey.__exit__(*exc_info)
return app, logged
def test_args_simple_ok(self):
# Simplest case that works
cmdline = "qp %s" % self.dir
app = ConsoleApp(cmdline.split())
self.assertEqual("qp", app.script_name)
self.assertFalse(app._error)
self.assertEqual(self.dir, app.queue_path)
self.assertEqual("localhost", app.hostname)
self.assertEqual(25, app.port)
self.assertEqual(None, app.username)
self.assertEqual(None, app.password)
self.assertFalse(app.force_tls)
self.assertFalse(app.no_tls)
self.assertFalse(app.debug_smtp)
def test_args_simple_error(self):
# Simplest case that doesn't work
cmdline = "qp"
app, logged = self._captureLoggedErrors(cmdline)
self.assertEqual("qp", app.script_name)
self.assertTrue(app._error)
self.assertEqual(None, app.queue_path)
self.assertEqual("localhost", app.hostname)
self.assertEqual(25, app.port)
self.assertEqual(None, app.username)
self.assertEqual(None, app.password)
self.assertFalse(app.force_tls)
self.assertFalse(app.no_tls)
self.assertFalse(app.debug_smtp)
self.assertEqual(len(logged), 1)
app.main()
def test_args_full_monty(self):
# Use (almost) all of the options
cmdline = """qp --hostname foo --port 75
--username chris --password rossi --force-tls
--debug-smtp --ssl
%s""" % self.dir
app = ConsoleApp(cmdline.split())
self.assertEqual("qp", app.script_name)
self.assertFalse(app._error)
self.assertEqual(self.dir, app.queue_path)
self.assertEqual("foo", app.hostname)
self.assertEqual(75, app.port)
self.assertEqual("chris", app.username)
self.assertEqual("rossi", app.password)
self.assertTrue(app.force_tls)
self.assertTrue(app.ssl)
self.assertFalse(app.no_tls)
self.assertTrue(app.debug_smtp)
def test_args_username_no_password(self):
# Test username without password
cmdline = "qp --username chris %s" % self.dir
app, logged = self._captureLoggedErrors(cmdline)
self.assertTrue(app._error)
self.assertEqual(len(logged), 1)
def test_args_force_tls_no_tls(self):
# Test force_tls and no_tls
cmdline = "qp --force-tls --no-tls %s" % self.dir
app, logged = self._captureLoggedErrors(cmdline)
self.assertTrue(app._error)
self.assertEqual(len(logged), 1)
def test_args_hostname_no_hostname(self):
cmdline = 'qp %s --hostname' % self.dir
app, logged = self._captureLoggedErrors(cmdline)
self.assertTrue(app._error)
#.........这里部分代码省略.........
示例14: Mailer
class Mailer(object):
"""
Manages sending of email messages.
:param host: SMTP hostname
:param port: SMTP port
:param username: SMTP username
:param password: SMPT password
:param tls: use TLS
:param ssl: use SSL
:param keyfile: SSL key file
:param certfile: SSL certificate file
:param queue_path: path to maildir for queued messages
:param default_sender: default "from" address
:param sendmail_app: path to "sendmail" binary.
repoze defaults to "/usr/sbin/sendmail"
:param sendmail_template: custom commandline template passed to sendmail
binary, defaults to'["{sendmail_app}", "-t", "-i", "-f", "{sender}"]'
:param debug: SMTP debug level
"""
def __init__(self,
host='localhost',
port=25,
username=None,
password=None,
tls=False,
ssl=False,
keyfile=None,
certfile=None,
queue_path=None,
default_sender=None,
sendmail_app=None,
sendmail_template=None,
debug=0):
if ssl:
self.smtp_mailer = SMTP_SSLMailer(
hostname=host,
port=port,
username=username,
password=password,
no_tls=not(tls),
force_tls=tls,
debug_smtp=debug,
keyfile=keyfile,
certfile=certfile)
else:
self.smtp_mailer = SMTPMailer(
hostname=host,
port=port,
username=username,
password=password,
no_tls=not(tls),
force_tls=tls,
debug_smtp=debug)
self.direct_delivery = DirectMailDelivery(self.smtp_mailer)
if queue_path:
self.queue_delivery = QueuedMailDelivery(queue_path)
else:
self.queue_delivery = None
self.sendmail_mailer = SendmailMailer(sendmail_app, sendmail_template)
self.sendmail_delivery = DirectMailDelivery(self.sendmail_mailer)
self.default_sender = default_sender
@classmethod
def from_settings(cls, settings, prefix='mail.'):
"""
Creates a new instance of **Mailer** from settings dict.
:param settings: a settings dict-like
:param prefix: prefix separating **pyramid_mailer** settings
"""
settings = settings or {}
kwarg_names = [prefix + k for k in (
'host', 'port', 'username',
'password', 'tls', 'ssl', 'keyfile',
'certfile', 'queue_path', 'debug', 'default_sender')]
size = len(prefix)
kwargs = dict(((k[size:], settings[k]) for k in settings.keys() if
k in kwarg_names))
for key in ('tls', 'ssl'):
val = kwargs.get(key)
if val:
kwargs[key] = asbool(val)
return cls(**kwargs)
#.........这里部分代码省略.........
示例15: bounce
def bounce(self, mto, msg):
QueuedMailDelivery.send(self, self.bounce_from, mto, msg)