本文整理汇总了Python中email.message.set_payload方法的典型用法代码示例。如果您正苦于以下问题:Python message.set_payload方法的具体用法?Python message.set_payload怎么用?Python message.set_payload使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类email.message
的用法示例。
在下文中一共展示了message.set_payload方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send
# 需要导入模块: from email import message [as 别名]
# 或者: from email.message import set_payload [as 别名]
def send(
sender, to,
subject='None',
body='None',
server='localhost'
):
"""sends a message."""
message = email.message.Message()
message['To'] = to
message['From'] = sender
message['Subject'] = subject
message.set_payload(body)
server = smtplib.SMTP(server)
try:
return server.sendmail(sender, to, message.as_string())
finally:
server.quit()
示例2: _get_upload_content
# 需要导入模块: from email import message [as 别名]
# 或者: from email.message import set_payload [as 别名]
def _get_upload_content(field_storage):
"""Returns an `email.Message` that contains the values of the file transfer.
This method decodes the content of the field storage and creates a new
`email.Message`.
Args:
field_storage: `cgi.FieldStorage` that represents an uploaded blob.
Returns:
An `email.message.Message` that lists the upload information.
"""
message = email.message.Message()
message.add_header(
'content-transfer-encoding',
field_storage.headers.getheader('Content-Transfer-Encoding', ''))
message.set_payload(field_storage.file.read())
payload = message.get_payload(decode=True)
return email.message_from_string(payload)
示例3: test_terminating_newline
# 需要导入模块: from email import message [as 别名]
# 或者: from email.message import set_payload [as 别名]
def test_terminating_newline(self):
message = email.message.Message()
message['From'] = 'john@example.com'
message.set_payload('No newline at the end')
i = self._box.add(message)
# A newline should have been appended to the payload
message = self._box.get(i)
self.assertEqual(message.get_payload(), 'No newline at the end\n')
示例4: compat32_message
# 需要导入模块: from email import message [as 别名]
# 或者: from email.message import set_payload [as 别名]
def compat32_message(request):
message = email.message.Message()
message["To"] = email.header.Header("recipient@example.com")
message["From"] = email.header.Header("sender@example.com")
message["Subject"] = "A message"
message.set_payload("Hello World")
return message