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