本文整理汇总了Python中email.mime.message.MIMEMessage.add_header方法的典型用法代码示例。如果您正苦于以下问题:Python MIMEMessage.add_header方法的具体用法?Python MIMEMessage.add_header怎么用?Python MIMEMessage.add_header使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类email.mime.message.MIMEMessage
的用法示例。
在下文中一共展示了MIMEMessage.add_header方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bounce
# 需要导入模块: from email.mime.message import MIMEMessage [as 别名]
# 或者: from email.mime.message.MIMEMessage import add_header [as 别名]
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)