本文整理匯總了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