當前位置: 首頁>>代碼示例>>Python>>正文


Python message.set_payload方法代碼示例

本文整理匯總了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() 
開發者ID:PacktPublishing,項目名稱:Expert-Python-Programming_Second-Edition,代碼行數:20,代碼來源:mailer.py

示例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) 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:21,代碼來源:blobstore.py

示例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') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:11,代碼來源:test_mailbox.py

示例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 
開發者ID:cole,項目名稱:aiosmtplib,代碼行數:10,代碼來源:conftest.py


注:本文中的email.message.set_payload方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。