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


Python SMTP.ehlo_or_helo_if_needed方法代码示例

本文整理汇总了Python中smtplib.SMTP.ehlo_or_helo_if_needed方法的典型用法代码示例。如果您正苦于以下问题:Python SMTP.ehlo_or_helo_if_needed方法的具体用法?Python SMTP.ehlo_or_helo_if_needed怎么用?Python SMTP.ehlo_or_helo_if_needed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在smtplib.SMTP的用法示例。


在下文中一共展示了SMTP.ehlo_or_helo_if_needed方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: flush

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import ehlo_or_helo_if_needed [as 别名]
    def flush(self):
        from smtplib import SMTP
        import settings, logging

        if not self.messages:
            return

        msg = 'To: ' + settings.to_addr + '\n'
        msg += 'From: ' + settings.from_addr + '\n'
        if len(self.messages) == 1:
            msg += 'Subject: mmonitor: ' + self.messages[0][:200] + '\n'
        else:
            msg += 'Subject: mmonitor: multiple notices\n'
        msg += '\n\n'
        msg += '\n'.join(self.messages)
        msg += '\n\n'

        logging.info('sending mail:\n%s', '\n'.join(self.messages))
        smtp = SMTP(settings.smtp_host, settings.smtp_port)
        if settings.smtp_tls:
            smtp.starttls()
        smtp.ehlo_or_helo_if_needed()
        if settings.smtp_user:
            smtp.login(settings.smtp_user, settings.smtp_password)
        smtp.sendmail(settings.from_addr, settings.to_addr, msg)
        smtp.close()
        self.messages = []
开发者ID:mixpanel,项目名称:mmonitor,代码行数:29,代码来源:mail.py

示例2: connect

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import ehlo_or_helo_if_needed [as 别名]
    def connect(self):
        """Connect the SMTP Server"""
        smtp = SMTP(smart_str(self.host), int(self.port))
        smtp.ehlo_or_helo_if_needed()
        if self.tls:
            smtp.starttls()
            smtp.ehlo_or_helo_if_needed()

        if self.user or self.password:
            smtp.login(smart_str(self.user), smart_str(self.password))
        return smtp
开发者ID:aaloy,项目名称:emencia-django-newsletter,代码行数:13,代码来源:models.py

示例3: handle

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import ehlo_or_helo_if_needed [as 别名]
def handle(to='[email protected]', sender = '[email protected]', body = 'mierda'):
    """
    Forward a message via an authenticated SMTP connection with
    starttls.
    """
    conn = SMTP(SMTP_HOST, 25, 'localhost')

    conn.starttls()
    conn.ehlo_or_helo_if_needed()
    conn.login(SMTP_USERNAME, SMTP_PASSWORD)
    conn.sendmail(sender, to, body)
    conn.quit()
开发者ID:skarone,项目名称:PipeL,代码行数:14,代码来源:mailServer.py

示例4: _prompt_smtp_data

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import ehlo_or_helo_if_needed [as 别名]
    def _prompt_smtp_data(self, dev=False):
        def _get_default_smtp(custom_host=None):
            if custom_host:
                candidates = [(custom_host, 25), (custom_host, 587)]
            else:
                candidates = [('127.0.0.1', 25), ('127.0.0.1', 587)]
            if dev:
                candidates.insert(0, (custom_host or '127.0.0.1', 1025))
            for host, port in candidates:
                try:
                    SMTP(host, port, timeout=3).close()
                except Exception:
                    continue
                return host, port
            return '', ''

        first = True
        default_smtp_host, default_smtp_port = _get_default_smtp()
        smtp_user = ''
        while True:
            smtp_host = _prompt('SMTP host', default=default_smtp_host,
                                help=('Indico needs an SMTP server to send emails.' if first else None))
            if smtp_host != default_smtp_host:
                default_smtp_port = _get_default_smtp(smtp_host)[1]
            smtp_port = int(_prompt('SMTP port', default=unicode(default_smtp_port or 25)))
            smtp_user = _prompt('SMTP username', default=smtp_user, required=False,
                                help=('If your SMTP server requires authentication, '
                                      'enter the username now.' if first else None))
            smtp_password = _prompt('SMTP password', password=True) if smtp_user else ''
            first = False
            # Test whether we can connect
            try:
                smtp = SMTP(smtp_host, smtp_port, timeout=10)
                smtp.ehlo_or_helo_if_needed()
                if smtp_user and smtp_password:
                    smtp.starttls()
                    smtp.login(smtp_user, smtp_password)
                smtp.quit()
            except Exception as exc:
                _warn('SMTP connection failed: ' + unicode(exc))
                if not click.confirm('Keep these settings anyway?'):
                    default_smtp_host = smtp_host
                    default_smtp_port = smtp_port
                    continue
            self.smtp_host = smtp_host
            self.smtp_port = smtp_port
            self.smtp_user = smtp_user
            self.smtp_password = smtp_password
            break
开发者ID:ThiefMaster,项目名称:indico,代码行数:51,代码来源:setup.py

示例5: send_error

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import ehlo_or_helo_if_needed [as 别名]
def send_error(ex, config):
    body = 'Error type: ' + type(ex).__name__ + '\nMessage: '
    for arg in ex.args:
        body += arg + '\n'
    msg = MIMEText(body)
    msg['Subject'] = 'name.com Update Error'
    msg['From'] = 'donotreply'
    msg['To'] = config['email']

    server = SMTP(config['smtp'])
    server.ehlo_or_helo_if_needed()
    server.starttls()
    server.login(config['smtpuser'], config['smtppassword'])
    server.send_message(msg)
    server.quit()
开发者ID:davidalk,项目名称:dnsrecord-update,代码行数:17,代码来源:dnsrec_update.py

示例6: _conectar

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import ehlo_or_helo_if_needed [as 别名]
 def _conectar(self):
     """
     Rutina de conexión a un servidor SMTP.
     :return:
     """
     try:
         # Conexion con el servidor smtp y procesos para el protocolo.
         server = SMTP(self.smtp_host, self.smtp_port)
         server.ehlo_or_helo_if_needed()  # helo en serv no-ESMTP
         server.starttls()  # Si servidor no lo habilita, yerra.
         server.ehlo_or_helo_if_needed()
         server.login(self.email_origen, self.passw)
         self._estadoconexion(nuevo_serv=server)
     except SMTPException as smtpe:
         raise
     except:
         raise
开发者ID:carlos-gs,项目名称:MiStuRe,代码行数:19,代码来源:mailing.py


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