本文整理汇总了Python中email.mime.multipart.MIMEMultipart.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python MIMEMultipart.__init__方法的具体用法?Python MIMEMultipart.__init__怎么用?Python MIMEMultipart.__init__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类email.mime.multipart.MIMEMultipart
的用法示例。
在下文中一共展示了MIMEMultipart.__init__方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from email.mime.multipart import MIMEMultipart [as 别名]
# 或者: from email.mime.multipart.MIMEMultipart import __init__ [as 别名]
def __init__(self, subject='', body='', from_email=None, to=None, bcc=None,
connection=None, attachments=None, headers=None, alternatives=None,
cc=None, reply_to=None):
"""
Initialize a single email message (which can be sent to multiple
recipients).
All strings used to create the message can be unicode strings (or UTF-8
bytestrings). The SafeMIMEText class will handle any necessary encoding
conversions.
"""
super(EmailMultiAlternatives, self).__init__(
subject, body, from_email, to, bcc, connection, attachments,
headers, cc, reply_to,
)
self.alternatives = alternatives or []
示例2: __init__
# 需要导入模块: from email.mime.multipart import MIMEMultipart [as 别名]
# 或者: from email.mime.multipart.MIMEMultipart import __init__ [as 别名]
def __init__(self, _text, _subtype='plain', _charset=None):
self.encoding = _charset
if _charset == 'utf-8':
# Unfortunately, Python < 3.5 doesn't support setting a Charset instance
# as MIMEText init parameter (http://bugs.python.org/issue16324).
# We do it manually and trigger re-encoding of the payload.
MIMEText.__init__(self, _text, _subtype, None)
del self['Content-Transfer-Encoding']
has_long_lines = any(len(l) > RFC5322_EMAIL_LINE_LENGTH_LIMIT for l in _text.splitlines())
# Quoted-Printable encoding has the side effect of shortening long
# lines, if any (#22561).
self.set_payload(_text, utf8_charset_qp if has_long_lines else utf8_charset)
self.replace_header('Content-Type', 'text/%s; charset="%s"' % (_subtype, _charset))
elif _charset is None:
# the default value of '_charset' is 'us-ascii' on Python 2
MIMEText.__init__(self, _text, _subtype)
else:
MIMEText.__init__(self, _text, _subtype, _charset)
示例3: __init__
# 需要导入模块: from email.mime.multipart import MIMEMultipart [as 别名]
# 或者: from email.mime.multipart.MIMEMultipart import __init__ [as 别名]
def __init__(self, subject='', body='', from_email=None, to=None, bcc=None,
connection=None, attachments=None, headers=None, alternatives=None,
cc=None, reply_to=None):
"""
Initialize a single email message (which can be sent to multiple
recipients).
All strings used to create the message can be unicode strings (or UTF-8
bytestrings). The SafeMIMEText class will handle any necessary encoding
conversions.
"""
super(EmailMultiAlternatives, self).__init__(
subject, body, from_email, to, bcc, connection, attachments,
headers, cc, reply_to,
)
self.alternatives = alternatives or []
示例4: __init__
# 需要导入模块: from email.mime.multipart import MIMEMultipart [as 别名]
# 或者: from email.mime.multipart.MIMEMultipart import __init__ [as 别名]
def __init__(self, protocol, micalg, boundary=None, _subparts=None):
"""
Initialize the multipart/signed message.
:param boundary: the multipart boundary string. By default it is
calculated as needed.
:type boundary: str
:param _subparts: a sequence of initial subparts for the payload. It
must be an iterable object, such as a list. You can always
attach new subparts to the message by using the attach() method.
:type _subparts: iterable
"""
MIMEMultipart.__init__(
self, _subtype='signed', boundary=boundary,
_subparts=_subparts)
self.set_param('protocol', protocol)
self.set_param('micalg', micalg)
示例5: __init__
# 需要导入模块: from email.mime.multipart import MIMEMultipart [as 别名]
# 或者: from email.mime.multipart.MIMEMultipart import __init__ [as 别名]
def __init__(self, _text, _subtype='plain', _charset=None):
self.encoding = _charset
if _charset == 'utf-8':
# Unfortunately, Python < 3.5 doesn't support setting a Charset instance
# as MIMEText init parameter (http://bugs.python.org/issue16324).
# We do it manually and trigger re-encoding of the payload.
MIMEText.__init__(self, _text, _subtype, None)
del self['Content-Transfer-Encoding']
# Workaround for versions without http://bugs.python.org/issue19063
if (3, 2) < sys.version_info < (3, 3, 4):
payload = _text.encode(utf8_charset.output_charset)
self._payload = payload.decode('ascii', 'surrogateescape')
self.set_charset(utf8_charset)
else:
self.set_payload(_text, utf8_charset)
self.replace_header('Content-Type', 'text/%s; charset="%s"' % (_subtype, _charset))
elif _charset is None:
# the default value of '_charset' is 'us-ascii' on Python 2
MIMEText.__init__(self, _text, _subtype)
else:
MIMEText.__init__(self, _text, _subtype, _charset)
示例6: __init__
# 需要导入模块: from email.mime.multipart import MIMEMultipart [as 别名]
# 或者: from email.mime.multipart.MIMEMultipart import __init__ [as 别名]
def __init__(self, _text, _subtype='plain', _charset=None):
self.encoding = _charset
if _charset == 'utf-8':
# Unfortunately, Python doesn't yet pass a Charset instance as
# MIMEText init parameter to set_payload().
# http://bugs.python.org/issue27445
# We do it manually and trigger re-encoding of the payload.
if six.PY3 and isinstance(_text, bytes):
# Sniffing encoding would fail with bytes content in MIMEText.__init__.
_text = _text.decode('utf-8')
MIMEText.__init__(self, _text, _subtype, None)
del self['Content-Transfer-Encoding']
has_long_lines = any(len(l) > RFC5322_EMAIL_LINE_LENGTH_LIMIT for l in _text.splitlines())
# Quoted-Printable encoding has the side effect of shortening long
# lines, if any (#22561).
self.set_payload(_text, utf8_charset_qp if has_long_lines else utf8_charset)
self.replace_header('Content-Type', 'text/%s; charset="%s"' % (_subtype, _charset))
elif _charset is None:
# the default value of '_charset' is 'us-ascii' on Python 2
MIMEText.__init__(self, _text, _subtype)
else:
MIMEText.__init__(self, _text, _subtype, _charset)
示例7: __init__
# 需要导入模块: from email.mime.multipart import MIMEMultipart [as 别名]
# 或者: from email.mime.multipart.MIMEMultipart import __init__ [as 别名]
def __init__(self, subject='', body='', from_email=None, to=None, bcc=None,
connection=None, attachments=None, headers=None, alternatives=None,
cc=None, reply_to=None):
"""
Initialize a single email message (which can be sent to multiple
recipients).
All strings used to create the message can be unicode strings (or UTF-8
bytestrings). The SafeMIMEText class will handle any necessary encoding
conversions.
"""
to = self.clean_list(to)
super(EmailMultiAlternatives, self).__init__(
subject, body, from_email, to, bcc, connection, attachments,
headers, cc, reply_to,
)
self.alternatives = alternatives or []