本文整理汇总了Python中email.mime.message.MIMEMessage类的典型用法代码示例。如果您正苦于以下问题:Python MIMEMessage类的具体用法?Python MIMEMessage怎么用?Python MIMEMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MIMEMessage类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bounce
def bounce(self, err='Error!', recipient=None):
"""Generate a bounce message with the given error message."""
text = _('email_text') % err
html = _('email_html') % err
self._msg.attach(MIMEText(text, 'plain', 'utf-8'))
self._msg.attach(MIMEText(html, 'html', 'utf-8'))
# Stick it all in an envelope.
envelope = MIMEMultipart('mixed')
envelope.attach(self._msg)
# If present, attach the entire incoming email.
if self._incoming is not None:
inc_msg = MIMEMessage(self._incoming)
inc_msg.add_header('Content-Disposition', 'attachment',
filename='%s.eml' % self._incoming['subject'])
envelope.attach(inc_msg)
if recipient is None and self._incoming:
recipient = self._incoming.get('reply-to',
self._incoming.get('from'))
envelope['From'] = settings.MAILTOFAX_EMAIL
envelope['To'] = recipient
envelope['Subject'] = _('subject') % (self._incoming['subject'] if
self._incoming else '')
if self._incoming:
envelope['In-Reply-To'] = self._incoming['message-id']
#print self._msg.as_string()
smtp = smtplib.SMTP(settings.SMTP_SERVER['host'],
settings.SMTP_SERVER.get('port') or 25)
if settings.SMTP_SERVER.get('tls'):
smtp.starttls()
if settings.SMTP_SERVER.get('user'):
smtp.login(settings.SMTP_SERVER['user'],
settings.SMTP_SERVER['password'])
smtp.sendmail(envelope['From'], [envelope['To']],
envelope.as_string())
sys.exit(1)
示例2: __setitem__
def __setitem__(self, name, val):
# message/rfc822 attachments must be ASCII
name, val = forbid_multi_line_headers(name, val, 'ascii')
MIMEMessage.__setitem__(self, name, val)
示例3:
from __future__ import unicode_literals