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


Python message.MIMEMessage类代码示例

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

示例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)
开发者ID:0xool,项目名称:DjangoTutorial,代码行数:4,代码来源:message.py

示例3:

from __future__ import unicode_literals
开发者ID:letouriste001,项目名称:SmartForest_2.0,代码行数:1,代码来源:message.py


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