本文整理汇总了Python中pyramid_mailer.message.Message.as_string方法的典型用法代码示例。如果您正苦于以下问题:Python Message.as_string方法的具体用法?Python Message.as_string怎么用?Python Message.as_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid_mailer.message.Message
的用法示例。
在下文中一共展示了Message.as_string方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_repoze_sendmail_send_to_queue_functional
# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import as_string [as 别名]
def test_repoze_sendmail_send_to_queue_functional(self):
# functest that emulates the interaction between pyramid_mailer and
# repoze.maildir.add and queuedelivery.send.
import tempfile
from email.generator import Generator
from email.parser import Parser
from pyramid_mailer.message import Message
from pyramid_mailer.message import Attachment
from repoze.sendmail.encoding import cleanup_message
from repoze.sendmail.delivery import copy_message
def checkit(msg):
self.assertEqual(
msg['Content-Type'],
'text/plain; charset="iso-8859-1"'
)
self.assertEqual(
msg['Content-Transfer-Encoding'], transfer_encoding)
payload = msg.get_payload()
self.assertEqual(payload, expected)
charset = 'iso-8859-1'
text_encoded = b'LaPe\xf1a'
text = text_encoded.decode(charset)
expected = _qencode(text_encoded).decode('ascii')
transfer_encoding = 'quoted-printable'
body = Attachment(
data=text,
transfer_encoding=transfer_encoding
)
msg = Message(
subject="testing",
sender="[email protected]",
recipients=["[email protected]"],
body=body
)
# done in pyramid_mailer via mailer/send_to_queue
msg = msg.to_message()
msg.as_string()
checkit(msg)
# done in repoze.sendmail via delivery/AbstractMailDelivery/send
cleanup_message(msg)
checkit(msg)
# done in repoze.sendmail via
# delivery/AbstractMailDelivery/createDataManager
msg_copy = copy_message(msg)
checkit(msg_copy)
try:
# emulate what repoze.sendmail maildir.py/add does
fn = tempfile.mktemp()
fd = os.open(fn,
os.O_CREAT|os.O_EXCL|os.O_WRONLY,
0o600
)
with os.fdopen(fd, 'w') as f:
writer = Generator(f)
writer.flatten(msg_copy)
# emulate what repoze.sendmail.queue _parseMessage does
with open(fn) as foo:
parser = Parser()
reconstituted = parser.parse(foo)
checkit(reconstituted)
finally: # pragma: no cover
try:
os.remove(fn)
except:
pass