当前位置: 首页>>代码示例>>Python>>正文


Python MIMEMessage.add_header方法代码示例

本文整理汇总了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)
开发者ID:maayanderooy,项目名称:mailtofax,代码行数:44,代码来源:mailtofax.py


注:本文中的email.mime.message.MIMEMessage.add_header方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。