本文整理汇总了Python中repoze.sendmail.delivery.DirectMailDelivery.send方法的典型用法代码示例。如果您正苦于以下问题:Python DirectMailDelivery.send方法的具体用法?Python DirectMailDelivery.send怎么用?Python DirectMailDelivery.send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类repoze.sendmail.delivery.DirectMailDelivery
的用法示例。
在下文中一共展示了DirectMailDelivery.send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_alternate_transaction_manager
# 需要导入模块: from repoze.sendmail.delivery import DirectMailDelivery [as 别名]
# 或者: from repoze.sendmail.delivery.DirectMailDelivery import send [as 别名]
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)
示例2: testRefusingMailerDiesInVote
# 需要导入模块: from repoze.sendmail.delivery import DirectMailDelivery [as 别名]
# 或者: from repoze.sendmail.delivery.DirectMailDelivery import send [as 别名]
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()
示例3: run
# 需要导入模块: from repoze.sendmail.delivery import DirectMailDelivery [as 别名]
# 或者: from repoze.sendmail.delivery.DirectMailDelivery import send [as 别名]
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)
示例4: test_send
# 需要导入模块: from repoze.sendmail.delivery import DirectMailDelivery [as 别名]
# 或者: from repoze.sendmail.delivery.DirectMailDelivery import send [as 别名]
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, [])
示例5: sendAddEmail
# 需要导入模块: from repoze.sendmail.delivery import DirectMailDelivery [as 别名]
# 或者: from repoze.sendmail.delivery.DirectMailDelivery import send [as 别名]
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)
示例6: test_send
# 需要导入模块: from repoze.sendmail.delivery import DirectMailDelivery [as 别名]
# 或者: from repoze.sendmail.delivery.DirectMailDelivery import send [as 别名]
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, [])
示例7: test_abort
# 需要导入模块: from repoze.sendmail.delivery import DirectMailDelivery [as 别名]
# 或者: from repoze.sendmail.delivery.DirectMailDelivery import send [as 别名]
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,[])
示例8: testSend
# 需要导入模块: from repoze.sendmail.delivery import DirectMailDelivery [as 别名]
# 或者: from repoze.sendmail.delivery.DirectMailDelivery import send [as 别名]
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, [])
示例9: test_send_returns_messageId
# 需要导入模块: from repoze.sendmail.delivery import DirectMailDelivery [as 别名]
# 或者: from repoze.sendmail.delivery.DirectMailDelivery import send [as 别名]
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)
示例10: test_send_returns_messageId
# 需要导入模块: from repoze.sendmail.delivery import DirectMailDelivery [as 别名]
# 或者: from repoze.sendmail.delivery.DirectMailDelivery import send [as 别名]
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)
示例11: testBrokenMailerErrorsAreEaten
# 需要导入模块: from repoze.sendmail.delivery import DirectMailDelivery [as 别名]
# 或者: from repoze.sendmail.delivery.DirectMailDelivery import send [as 别名]
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()
示例12: testSMTPErrorInSendDoesntAbortTPC
# 需要导入模块: from repoze.sendmail.delivery import DirectMailDelivery [as 别名]
# 或者: from repoze.sendmail.delivery.DirectMailDelivery import send [as 别名]
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()
示例13: Mailer
# 需要导入模块: from repoze.sendmail.delivery import DirectMailDelivery [as 别名]
# 或者: from repoze.sendmail.delivery.DirectMailDelivery import send [as 别名]
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)
#.........这里部分代码省略.........
示例14: test_savepoint
# 需要导入模块: from repoze.sendmail.delivery import DirectMailDelivery [as 别名]
# 或者: from repoze.sendmail.delivery.DirectMailDelivery import send [as 别名]
def test_savepoint(self):
import transaction
mailer = _makeMailerStub()
delivery = DirectMailDelivery(mailer)
( fromaddr , toaddrs ) = fromaddr_toaddrs()
bodies_good = {}
bodies_bad = {}
for i in ( 1,3,5, ):
bodies_good[i] = 'Sample Body - %s | Good' % i
for i in ( 2,4,6, ):
bodies_bad[i] = 'Sample Body - %s | Bad' % i
bodies_all = dict(list(bodies_good.items()) +
list(bodies_bad.items()))
transaction.begin()
for i in range(1,7) :
sp = transaction.savepoint()
body = bodies_all[i]
message = sample_message(body=body)
msgid = delivery.send(fromaddr, toaddrs, message)
self.assertEqual(msgid, '<[email protected]>')
self.assertEqual(mailer.sent_messages, [])
if i in bodies_bad :
sp.rollback()
# we shouldn't have sent anything
self.assertEqual(mailer.sent_messages, [])
# so now let's commit
transaction.commit()
# make sure we have the right number of messages
self.assertEqual(len(mailer.sent_messages), len(bodies_good.values()))
# generate our expected body
bodies_expected = bodies_good.values()
# make sure our bodies are only good
for f, t, m in mailer.sent_messages :
self.assertTrue(m._payload in bodies_expected)
## ok, can we do multiple savepoints ?
active_transaction = transaction.manager.get()
mailer.sent_messages = []
transaction.begin()
sp_outer = transaction.savepoint()
for i in range(1,7) :
sp = transaction.savepoint()
body = bodies_all[i]
message = sample_message(body=body)
msgid = delivery.send(fromaddr, toaddrs, message)
self.assertEqual(msgid, '<[email protected]>')
self.assertEqual(mailer.sent_messages, [])
sp3 = transaction.savepoint()
sp3.rollback()
if i in bodies_bad :
sp.rollback()
sp_outer.rollback()
示例15: Mailer
# 需要导入模块: from repoze.sendmail.delivery import DirectMailDelivery [as 别名]
# 或者: from repoze.sendmail.delivery.DirectMailDelivery import send [as 别名]
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 for sendmail binary,
defaults to'["{sendmail_app}", "-t", "-i", "-f", "{sender}"]'
:param transaction_manager: a transaction manager to join with when
sending transactional emails
:param debug: SMTP debug level
"""
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)
@classmethod
def from_settings(cls, settings, prefix="mail."):
"""Create 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",
#.........这里部分代码省略.........