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


Python SMTP_SSL.ehlo方法代码示例

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


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

示例1: _send

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import ehlo [as 别名]
    def _send(self, email_addrs, msg):
        proto = self._conf['proto']
        assert proto in ('smtp', 'starttls', 'ssl'), \
            "Incorrect protocol: %s" % proto
        
        try:
            if proto == 'ssl':
                session = SMTP_SSL(self._conf['fqdn'], self._conf['port'])
            else:
                session = SMTP(self._conf['fqdn'], self._conf['port'])
            
            if proto == 'starttls':
                session.ehlo()
                session.starttls()
                session.ehlo()
            
            if self._conf['user'] is not None:
                session.login(self._conf['user'], self._conf['pass'])
            
            session.sendmail(self.sender, email_addrs, msg)
            session.quit()

        except Exception as e:  # pragma: no cover
            ''' '''
            print str(e)
开发者ID:iocast,项目名称:hook-server,代码行数:27,代码来源:webapp.py

示例2: send_mail

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import ehlo [as 别名]
def send_mail( message,  smtp_host, smtp_port, user = None, passwd = None,
    security = None ):
    '''
    Sends a message to a smtp server
    '''
    if security == 'SSL':
        if not HAS_SMTP_SSL:
            raise Exception('Sorry. For SMTP_SSL support you need Python >= 2.6')
        s = SMTP_SSL(smtp_host, smtp_port)
    else:
        s = SMTP(smtp_host, smtp_port)
    # s.set_debuglevel(10)
    s.ehlo()

    if security == 'TLS':
        s.starttls()
        s.ehlo()
    if user:
        s.login(user.encode('utf-8'), passwd.encode('utf-8'))

    to_addr_list = []

    if message['To']:
        to_addr_list.append(message['To'])
    if message['Cc']:
        to_addr_list.append(message['Cc'])
    if message['Bcc']:
        to_addr_list.append(message['Bcc'])

    to_addr_list = ','.join(to_addr_list).split(',')

    s.sendmail(message['From'], to_addr_list, message.as_string())
    s.close()
开发者ID:jadolg,项目名称:webpymail,代码行数:35,代码来源:mail_utils.py

示例3: connect_to_server

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import ehlo [as 别名]
    def connect_to_server(self):
        if self.tls == 'ssl':
            connection = SMTP_SSL(local_hostname=self.local_hostname, keyfile=self.keyfile,
                                  certfile=self.certfile, timeout=self.timeout)
        else:
            connection = SMTP(local_hostname=self.local_hostname, timeout=self.timeout)

        log.info("Connecting to SMTP server %s:%s", self.host, self.port)
        connection.set_debuglevel(self.debug)
        connection.connect(self.host, self.port)

        # Do TLS handshake if configured
        connection.ehlo()
        if self.tls in ('required', 'optional'):
            if connection.has_extn('STARTTLS'):
                connection.starttls(self.keyfile, self.certfile)
            elif self.tls == 'required':
                raise TransportException('TLS is required but not available on the server -- aborting')

        # Authenticate to server if necessary
        if self.username and self.password:
            log.info("Authenticating as %s", self.username)
            connection.login(self.username, self.password)

        self.connection = connection
        self.sent = 0
开发者ID:ormsbee,项目名称:marrow.mailer,代码行数:28,代码来源:smtp.py

示例4: sendMessage

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import ehlo [as 别名]
    def sendMessage(self, sender, password, recipient, subject, body, attachmentFilenames=[]):
        if type(attachmentFilenames) != list:
            attachmentFilenames = [attachmentFilenames]

        msg = MIMEMultipart()
        msg['Subject'] = subject
        msg['From'] = sender
        msg['To'] = recipient
        msg['Date'] = formatdate(localtime=True)

        msg.attach(MIMEText(body, 'html'))

        for filename in attachmentFilenames:
            part = MIMEBase('application', "octet-stream")
            part.set_payload(open(filename, "rb").read())
            Encoders.encode_base64(part)
            part.add_header('Content-Disposition', 'attachment; filename="%s"' % basename(filename))
            msg.attach(part)

        self.out.put("connecting...")
        mailServer = SMTP_SSL(self.smtpHost, 465)
        mailServer.ehlo()
        self.out.put("logging in...")
        mailServer.login(sender, password)
        self.out.put("sending...")
        mailServer.sendmail(sender, recipient, msg.as_string())  # raise if email is not sent
        mailServer.quit()
        self.out.put("done.")
开发者ID:CronWorks,项目名称:py-base,代码行数:30,代码来源:Emailer.py

示例5: testsettings

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import ehlo [as 别名]
def testsettings(host, port, login, password):
    host = host.encode('utf-8')
    port = int(port)
    login = login.encode('utf-8')
    password = password.encode('utf-8')

    try: # SSL
        smtp = SMTP_SSL(host, port)
        ret, _ = smtp.login(login, password)
        smtp.quit()

        if ret is 235: # 2.7.0 Authentication successful
            return True
    except (ssl.SSLError, SMTPException):
        pass

    try: # STARTTLS or plaintext
        smtp = SMTP(host, port)
        smtp.starttls()
        smtp.ehlo()
        ret, _ = smtp.login(login, password)
        smtp.quit()

        if ret is 235:
            return True
    except SMTPException:
        pass

    return False
开发者ID:turnkeylinux,项目名称:confconsole,代码行数:31,代码来源:mail_relay.py

示例6: _send

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import ehlo [as 别名]
    def _send(self, email_addr, msg):
        """Deliver an email using SMTP

        :param email_addr: recipient
        :type email_addr: str.
        :param msg: email text
        :type msg: str.
        """
        proto = self._conf["proto"]
        assert proto in ("smtp", "starttls", "ssl"), "Incorrect protocol: %s" % proto

        try:
            if proto == "ssl":
                log.debug("Setting up SSL")
                session = SMTP_SSL(self._conf["fqdn"], self._conf["port"])
            else:
                session = SMTP(self._conf["fqdn"], self._conf["port"])

            if proto == "starttls":
                log.debug("Sending EHLO and STARTTLS")
                session.ehlo()
                session.starttls()
                session.ehlo()

            if self._conf["user"] is not None:
                log.debug("Performing login")
                session.login(self._conf["user"], self._conf["pass"])

            log.debug("Sending")
            session.sendmail(self.sender, email_addr, msg)
            session.quit()
            log.info("Email sent")

        except Exception as e:  # pragma: no cover
            log.error("Error sending email: %s" % e, exc_info=True)
开发者ID:nonki7777,项目名称:bottle-cork,代码行数:37,代码来源:cork.py

示例7: _open

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import ehlo [as 别名]
 def _open(self):
     if self.conn:
         return
     conn = SMTP_SSL(self.config_d['smtp_host'],
                     self.config_d['smtp_port'])
     conn.ehlo()
     conn.login(self.config_d['smtp_user'],
                self.config_d['smtp_password'])
     self.conn = conn
开发者ID:headmin,项目名称:zentral,代码行数:11,代码来源:email.py

示例8: MailMin

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import ehlo [as 别名]
 def MailMin(self):
         smtp = SMTP_SSL(self.mail_info["hostname"])
         smtp.set_debuglevel(1)
         smtp.ehlo(self.mail_info["hostname"])
         smtp.login(self.mail_info["username"], self.mail_info["password"])
         msg = MIMEText(self.mail_text, "plain", self.mail_info["mail_encoding"])
         msg["Subject"] = Header(self.mail_subject,self. mail_info["mail_encoding"])
         msg["from"] =self. mail_info["from"]
         msg["to"] =','.join(self.to_mail)
         smtp.sendmail(self.mail_info["from"], self.to_mail, msg.as_string())
         smtp.quit()
开发者ID:cpj1352,项目名称:cpjspider,代码行数:13,代码来源:gemail.py

示例9: send_text

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import ehlo [as 别名]
def send_text(msg_str):
    msg = MIMEText(msg_str)

    msg['Subject'] = ""
    msg['From'] = "[email protected]"
    msg['To'] = "[email protected]"

    server = SMTP_SSL('smtp.mail.yahoo.com')
    server.ehlo()
    server.login("johnbert314", "Buster314")
    text = msg.as_string()
    server.sendmail("[email protected]", "[email protected]", text)
    server.quit()
开发者ID:JohnMcAninley,项目名称:Scripts,代码行数:15,代码来源:text.py

示例10: sendmail

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import ehlo [as 别名]
def sendmail(sender, to, subject, contents, texttype='plain'):
    Charset.add_charset(encode, Charset.QP, Charset.QP, encode)
    msg = MIMEText(contents, texttype, encode)
    msg['Subject'] = Header(subject.encode(encode), encode).encode()
    msg['From'] = sender
    msg['To'] = ', '.join(to)
    s = SMTP('smtp.exmail.qq.com')
    s.ehlo('smtp.exmail.qq.com')
    s.set_debuglevel(False)
    s.login('[email protected]','GMvsBWKwZty47LG2') # access code is generated from web (settings->account->wechat code)
    try:
        s.sendmail(sender, to, msg.as_string())
    finally:
        s.quit()
开发者ID:TAKSIM,项目名称:camp,代码行数:16,代码来源:utils.py

示例11: send_mail

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import ehlo [as 别名]
def send_mail(from_email: str, to: dict, subject: str, body: str, ):

    message = EmailMultiAlternatives(from_email=from_email, to=to, subject=subject, body=body, )

    connection_params = {'local_hostname': 'mail-proxy.keksik.com.ua', }

    try:
        connection = SMTP_SSL(
            host=settings.SEND_SMS_MAIL_ACCOUNT['server_smtp'],
            port=settings.SEND_SMS_MAIL_ACCOUNT['port_smtp'],
            **connection_params)

        if settings.SEND_SMS_MAIL_ACCOUNT['username'] \
                and settings.SEND_SMS_MAIL_ACCOUNT['password']:
            connection.login(
                settings.SEND_SMS_MAIL_ACCOUNT['username'],
                settings.SEND_SMS_MAIL_ACCOUNT['password'],
            )
            connection.ehlo()

    except (SMTPException, SMTPServerDisconnected) as e:
        logger.error('Exception(SMTPException, SMTPServerDisconnected): %s' % e)
        return False

    except socket.error as e:
        logger.info('Exception(socket.error): %s' % e)
        return False

    try:
        # (Python3) msg --> convert to bytes
        connection.sendmail(from_addr=formataddr(('Asterisk Keksik', '[email protected]',), ),
                            to_addrs=[formataddr(('Менеджер магазина Keksik', '[email protected]',), ), ],
                            msg=message.message().as_string().encode(), )
        connection.quit()

        # Если мы письмо отправили то возвращаем True
        return True

    except SMTPSenderRefused as e:
        logger.info('SMTPSenderRefused: %s' % e)

    except SMTPDataError as e:
        logger.info('SMTPDataError: %s| messages: %s| smtp_code: %s| smtp_error: %s| args: %s' %
                    (e, e.message, e.smtp_code, e.smtp_error, e.args), )

    except Exception as e:
        logger.info('Exception1: %s' % e)

    # Если письмо не ушло то возвращаем False
    return False
开发者ID:AlexStarov,项目名称:Shop,代码行数:52,代码来源:utils.py

示例12: sendmail

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import ehlo [as 别名]
def sendmail(sender, to, subject, contents, texttype='html'):
    Charset.add_charset(encode, Charset.QP, Charset.QP, encode)
    msg = MIMEText(contents, texttype, encode)
    msg['Subject'] = Header(subject.encode(encode), encode).encode()
    msg['From'] = sender
    msg['To'] = ', '.join(to)
    s = SMTP('smtp.exmail.qq.com')
    s.set_debuglevel(False)
    s.ehlo('smtp.exmail.qq.com')
    s.login('[email protected]', '[email protected]')
    import pandas
    pandas.read_ex
    try:
        s.sendmail(sender, to, msg.as_string())
    finally:
        s.quit()
开发者ID:TAKSIM,项目名称:fwm,代码行数:18,代码来源:utils.py

示例13: send_mail

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import ehlo [as 别名]
def send_mail():
    smtp = SMTP_SSL(mailInfo["hostname"])
    smtp.set_debuglevel(1)
    smtp.ehlo(mailInfo["hostname"])
    smtp.login(mailInfo["username"], mailInfo["password"])

    msg = MIMEText(mailInfo["mailtext"], mailInfo["mailtype"],
                   mailInfo["mailencoding"])
    msg["Subject"] = Header(mailInfo["mailsubject"], mailInfo["mailencoding"])
    msg["from"] = mailInfo["from"]
    msg["to"] = mailInfo["to"]
    msg["Accept-Language"] = "zh-CN"
    msg["Accept-Charset"] = "ISO-8859-1,utf-8"
    smtp.sendmail(mailInfo["from"], mailInfo["to"], msg.as_string())

    smtp.quit()
开发者ID:PegasusWang,项目名称:collection_python,代码行数:18,代码来源:send_mail_demo.py

示例14: send_mail

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import ehlo [as 别名]
def send_mail(sessions):
	'''向指定的用户发送邮箱
	参数:
		build_mail构造邮件之后,传递一个邮件列表,将根据sessions中的每个msg发送
	'''
	smtp = SMTP_SSL(SERVER_HOST, SERVER_PORT)
	smtp.set_debuglevel(1)
	smtp.ehlo(SERVER_HOST)
	smtp.login(USERNAME, AUTHTOKEN)

	for session in sessions:
		regex = re.compile(r'<(.+)>', re.UNICODE)
		from_addr = regex.search(session['From']).group(1)
		to_addr   = regex.search(session['To']).group(1)
		smtp.sendmail(from_addr, to_addr, session.as_string())

	smtp.quit()
开发者ID:ilib0x00000000,项目名称:NULL,代码行数:19,代码来源:mailto.py

示例15: send_mails

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import ehlo [as 别名]
def send_mails(messages, host='localhost', port=25, user=None, password=None,
               starttls=False, ssl=False, ssl_key=None, ssl_cert=None,
               timeout=None):
    """
    Send ``messages``.

    :param Message messages: Message instance or list of Messages.
    :param str host:         hostname or ip of the SMTP server to use to send
                             the messages. Defaults to 'localhost'
    :param int port:         port the smtp server listens on. Defaults to 25.
                             Secure SMTP uses port 465, see ``ssl`` below.
    :param str user:         Username to authenticate with.
    :param str password:     Password for authentication.
    :param bool starttls:    If True, use STARTTLS. This is an SMTP extension
                             to initiate a secure connection with a SMTP server
                             listening on port 25.
    :param bool ssl:         Initialize a SSL protected connection to the
                             server. SSL protected SMTP typically runs on port
                             465. (Note that this is different then using the
                             ``starttls`` option).
    :param ssl_key str:      SSL private key file, PEM format
    :param ssl_cert str:     SSL certificate chain file, PEM format
    :param timeout int:      timeout in seconds
    """
    if ssl:
        server = SMTP_SSL(host, port, timeout=timeout,
                          keyfile=ssl_key, certfile=ssl_cert)
    else:
        server = SMTP(host, port, timeout=timeout)

    if starttls:
        server.ehlo()
        server.starttls()
        server.ehlo()

    if user and password:
        server.login(user, password)

    if isinstance(messages, Message):
        server.sendmail(*messages.compile())
    else:
        for m in messages:
            server.sendmail(*m.compile())

    server.quit()
开发者ID:johaness,项目名称:postamt,代码行数:47,代码来源:postamt.py


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