本文整理汇总了Python中repoze.sendmail.delivery.DirectMailDelivery类的典型用法代码示例。如果您正苦于以下问题:Python DirectMailDelivery类的具体用法?Python DirectMailDelivery怎么用?Python DirectMailDelivery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DirectMailDelivery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self):
'''
:ivar to_addr: The default recipient email address
Will be set to the configuration variable "email_to",
if configuration is available
:ivar from_addr: The default sender email address
Will be set to the configuration variable "admin_email_from",
if configuration is available
'''
self.to_addr = config.get('email_to')
self.from_addr = config.get('admin_email_from')
smtp_server = config.get('smtp_server')
smtp_use_tls = asbool(config.get('smtp_use_tls'))
smtp_username = config.get('smtp_username')
smtp_password = config.get('smtp_password')
test = asbool(config.get('test'))
if test:
log.debug('Using DummyDelivery()')
self.delivery = DummyDelivery()
else: # pragma: no cover
if smtp_server:
mailer = SMTPMailer(hostname=smtp_server,
username=smtp_username, password=smtp_password,
force_tls=smtp_use_tls)
log.debug('Using SMTPMailer(hostname=%s, ...)', smtp_server)
else:
mailer = SendmailMailer()
log.debug('Using SendmailMailer()')
self.delivery = DirectMailDelivery(mailer)
示例2: __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)
示例3: testRefusingMailerDiesInVote
def testRefusingMailerDiesInVote(self):
from repoze.sendmail.delivery import DirectMailDelivery
mailer = RefusingMailerStub()
delivery = DirectMailDelivery(mailer)
fromaddr = 'Jim <[email protected]'
toaddrs = ('Guido <[email protected]>',
'Steve <[email protected]>')
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)
try:
transaction.commit()
except:
if transaction.get()._voted:
# We voted for commit then failed, reraise
raise
else:
# We vetoed a commit, that's good.
pass
else:
self.fail("Did not raise an exception in vote")
finally:
# Clean up after ourselves
transaction.abort()
示例4: test_alternate_transaction_manager
def test_alternate_transaction_manager(self):
from repoze.sendmail.delivery import DirectMailDelivery
from email.message import Message
import transaction
mailer = _makeMailerStub()
delivery = DirectMailDelivery(mailer)
tm = transaction.TransactionManager()
delivery.transaction_manager = tm
fromaddr = "Jim <[email protected]>"
toaddrs = ("Guido <[email protected]>", "Steve <[email protected]>")
message = Message()
message["From"] = fromaddr
message["To"] = ",".join(toaddrs)
message["Date"] = "Date: Mon, 19 May 2003 10:17:36 -0400"
message["Subject"] = "example"
message.set_payload("This is just an example\n")
msgid = delivery.send(fromaddr, toaddrs, message)
transaction.commit()
self.assertEqual(len(mailer.sent_messages), 0)
t = tm.get()
data_manager = t._resources[0]
self.assertTrue(data_manager.transaction_manager is tm)
t.commit()
self.assertEqual(len(mailer.sent_messages), 1)
self.assertEqual(mailer.sent_messages[0][0], fromaddr)
self.assertEqual(mailer.sent_messages[0][1], toaddrs)
self.assertEqual(mailer.sent_messages[0][2].get_payload(), "This is just an example\n")
mailer.sent_messages = []
msgid = delivery.send(fromaddr, toaddrs, message)
tm.get().abort()
self.assertEqual(len(mailer.sent_messages), 0)
示例5: test_abort
def test_abort(self):
import transaction
mailer = _makeMailerStub()
delivery = DirectMailDelivery(mailer)
( fromaddr , toaddrs ) = fromaddr_toaddrs()
message = sample_message()
msgid = delivery.send(fromaddr, toaddrs, message)
self.assertEqual(msgid, '<[email protected]>')
self.assertEqual(mailer.sent_messages, [])
transaction.abort()
transaction.commit()
self.assertEqual(mailer.sent_messages,[])
示例6: __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
示例7: test_send_returns_messageId
def test_send_returns_messageId(self):
from repoze.sendmail.delivery import DirectMailDelivery
from email.message import Message
mailer = _makeMailerStub()
delivery = DirectMailDelivery(mailer)
fromaddr = 'Jim <[email protected]'
toaddrs = ('Guido <[email protected]>',
'Steve <[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['Subject'] = 'example'
message.set_payload('This is just an example\n')
msgid = delivery.send(fromaddr, toaddrs, message)
self.assertTrue('[email protected]' in msgid)
self.assertEqual(message['Message-Id'], msgid)
示例8: test_send_returns_messageId
def test_send_returns_messageId(self):
from repoze.sendmail.delivery import DirectMailDelivery
from email.message import Message
mailer = _makeMailerStub()
delivery = DirectMailDelivery(mailer)
fromaddr = "Jim <[email protected]"
toaddrs = ("Guido <[email protected]>", "Steve <[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["Subject"] = "example"
message.set_payload("This is just an example\n")
msgid = delivery.send(fromaddr, toaddrs, message)
self.assertTrue("[email protected]" in msgid)
self.assertEqual(message["Message-Id"], msgid)
示例9: run
def run(self):
other_threads = threading.enumerate()
other_threads.remove(threading.current_thread())
if self.name in [t.name for t in other_threads]:
return
mailer = SMTPMailer(port=config.SMTP_PORT)
delivery = DirectMailDelivery(mailer)
a = True
while True:
items = deepcopy(self.root)
for hash, search in items.iteritems():
if not search['active']:
continue
results = performSearch(self.root, search)
tell = []
for result in results:
key = result.copy()
del key['total_price']
del key['book_link']
if key not in search['told']:
tell.append(result)
search['told'].append(key)
if not tell:
continue
url = config.URL
remove_link = '%s/remove?email=%s&code=%s' % (url, search['email'], hash)
journies = []
for result in tell:
journey = config.JOURNEY_STR % result
journies.append(journey)
journies = config.JOURNEY_JOINER.join(journies)
message_text = config.EMAIL_MATCHES % {'journies': journies,
'remove_link': remove_link}
message = Message()
message.set_payload(message_text)
delivery.send(config.FROM_ADDR, [search['email'],], message)
transaction.commit()
time.sleep(20)
示例10: test_send
def test_send(self):
from repoze.sendmail.delivery import DirectMailDelivery
import transaction
from email.message import Message
mailer = _makeMailerStub()
delivery = DirectMailDelivery(mailer)
fromaddr = 'Jim <[email protected]'
toaddrs = ('Guido <[email protected]>',
'Steve <[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(mailer.sent_messages, [])
transaction.commit()
self.assertEqual(mailer.sent_messages,
[(fromaddr, toaddrs, message)])
mailer.sent_messages = []
msgid = delivery.send(fromaddr, toaddrs, message)
self.assertTrue('@' in msgid)
self.assertEqual(mailer.sent_messages, [])
transaction.commit()
self.assertEqual(len(mailer.sent_messages), 1)
self.assertEqual(mailer.sent_messages[0][0], fromaddr)
self.assertEqual(mailer.sent_messages[0][1], toaddrs)
self.assertEqual(mailer.sent_messages[0][2].get_payload(),
'This is just an example\n')
self.assertEqual(message['Message-Id'], msgid)
self.assertEqual(message['Message-Id'], ext_msgid)
mailer.sent_messages = []
msgid = delivery.send(fromaddr, toaddrs, message)
self.assertEqual(mailer.sent_messages, [])
transaction.abort()
self.assertEqual(mailer.sent_messages, [])
示例11: sendAddEmail
def sendAddEmail(request, email, hash, destinations):
mailer = SMTPMailer(port=config.SMTP_PORT)
delivery = DirectMailDelivery(mailer)
human_destinations = [config.IATA_CODE_MAP[d] for d in destinations]
if len(human_destinations)>1:
human_destinations = '%s and %s' % (', '.join(human_destinations[:-1]),
human_destinations[-1])
elif len(human_destinations)==1:
human_destinations = human_destinations[0]
confirm_link = request.relative_url('confirm?email=%s&code=%s' %
(urllib.quote(email),
urllib.quote(hash))
)
message_text = config.EMAIL_CONFIRM % \
{'destinations': human_destinations,
'confirm_link': confirm_link}
message = Message()
message.set_payload(message_text)
delivery.send(config.FROM_ADDR, [email,], message)
示例12: testBrokenMailerErrorsAreEaten
def testBrokenMailerErrorsAreEaten(self):
from repoze.sendmail.delivery import DirectMailDelivery
mailer = BrokenMailerStub()
delivery = DirectMailDelivery(mailer)
fromaddr = 'Jim <[email protected]'
toaddrs = ('Guido <[email protected]>',
'Steve <[email protected]>')
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)
try:
transaction.commit()
finally:
# Clean up after ourselves
transaction.abort()
示例13: test_send
def test_send(self):
from repoze.sendmail.delivery import DirectMailDelivery
import transaction
from email.message import Message
mailer = _makeMailerStub()
delivery = DirectMailDelivery(mailer)
fromaddr = "Jim <[email protected]"
toaddrs = ("Guido <[email protected]>", "Steve <[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(mailer.sent_messages, [])
transaction.commit()
self.assertEqual(mailer.sent_messages, [(fromaddr, toaddrs, message)])
mailer.sent_messages = []
msgid = delivery.send(fromaddr, toaddrs, message)
self.assertTrue("@" in msgid)
self.assertEqual(mailer.sent_messages, [])
transaction.commit()
self.assertEqual(len(mailer.sent_messages), 1)
self.assertEqual(mailer.sent_messages[0][0], fromaddr)
self.assertEqual(mailer.sent_messages[0][1], toaddrs)
self.assertEqual(mailer.sent_messages[0][2].get_payload(), "This is just an example\n")
self.assertEqual(message["Message-Id"], msgid)
self.assertEqual(message["Message-Id"], ext_msgid)
mailer.sent_messages = []
msgid = delivery.send(fromaddr, toaddrs, message)
self.assertEqual(mailer.sent_messages, [])
transaction.abort()
self.assertEqual(mailer.sent_messages, [])
示例14: testSend
def testSend(self):
from repoze.sendmail.delivery import DirectMailDelivery
mailer = MailerStub()
delivery = DirectMailDelivery(mailer)
fromaddr = 'Jim <[email protected]'
toaddrs = ('Guido <[email protected]>',
'Steve <[email protected]>')
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(mailer.sent_messages, [])
transaction.commit()
self.assertEquals(mailer.sent_messages,
[(fromaddr, toaddrs, opt_headers + message)])
mailer.sent_messages = []
msgid = delivery.send(fromaddr, toaddrs, message)
self.assert_('@' in msgid)
self.assertEquals(mailer.sent_messages, [])
transaction.commit()
self.assertEquals(len(mailer.sent_messages), 1)
self.assertEquals(mailer.sent_messages[0][0], fromaddr)
self.assertEquals(mailer.sent_messages[0][1], toaddrs)
self.assert_(mailer.sent_messages[0][2].endswith(message))
new_headers = mailer.sent_messages[0][2][:-len(message)]
self.assert_(new_headers.find('Message-Id: <%s>' % msgid) != -1)
mailer.sent_messages = []
msgid = delivery.send(fromaddr, toaddrs, opt_headers + message)
self.assertEquals(mailer.sent_messages, [])
transaction.abort()
self.assertEquals(mailer.sent_messages, [])
示例15: testSMTPErrorInSendDoesntAbortTPC
def testSMTPErrorInSendDoesntAbortTPC(self):
from repoze.sendmail.delivery import DirectMailDelivery
mailer = SMTPResponseExceptionMailerStub(505)
delivery = DirectMailDelivery(mailer)
fromaddr = 'Jim <[email protected]'
toaddrs = ('Guido <[email protected]>',
'Steve <[email protected]>')
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)
try:
transaction.commit()
except Exception as e:
self.fail(str(e))
finally:
# Clean up after ourselves
transaction.abort()