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


Python EmailMessage.set_payload方法代碼示例

本文整理匯總了Python中email.message.EmailMessage.set_payload方法的典型用法代碼示例。如果您正苦於以下問題:Python EmailMessage.set_payload方法的具體用法?Python EmailMessage.set_payload怎麽用?Python EmailMessage.set_payload使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在email.message.EmailMessage的用法示例。


在下文中一共展示了EmailMessage.set_payload方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: convert

# 需要導入模塊: from email.message import EmailMessage [as 別名]
# 或者: from email.message.EmailMessage import set_payload [as 別名]
def convert(filename):
    with open(filename, "r") as file:
        raws    = file.read().split("\n")
        subject = raws[0]
        body    = "\n".join(raws[1:])

        email = EmailMessage()
        email.set_payload(body,"utf8")
        email["Subject"] = subject

        return email
開發者ID:Fougere87,項目名稱:unsec,代碼行數:13,代碼來源:text_to_mail.py

示例2: add

# 需要導入模塊: from email.message import EmailMessage [as 別名]
# 或者: from email.message.EmailMessage import set_payload [as 別名]
 def add(self, location: str, content_type: str, payload: str, encoding: str = 'quoted-printable') -> None:
     resource = EmailMessage()
     if content_type == 'text/html':
         resource.add_header('Content-Type', 'text/html', charset='utf-8')
     else:
         resource['Content-Type'] = content_type
     if encoding == 'quoted-printable':
         resource['Content-Transfer-Encoding'] = encoding
         resource.set_payload(quopri.encodestring(payload.encode()))
     elif encoding == 'base64':
         resource['Content-Transfer-Encoding'] = encoding
         resource.set_payload(base64.b64encode(payload))
     elif encoding == 'base64-encoded':  # Already base64 encoded
         resource['Content-Transfer-Encoding'] = 'base64'
         resource.set_payload(payload)
     else:
         raise ValueError('invalid encoding')
     resource['Content-Location'] = location
     self._msg.attach(resource)
開發者ID:bosondata,項目名稱:prerender,代碼行數:21,代碼來源:mhtml.py


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