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


Python SMTP_SSL.select方法代码示例

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


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

示例1: send_mail

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import select [as 别名]
def send_mail(from_, to, subject, text, html, smtp_server, username, password):
    try:
        # Record the MIME types of both parts - text/plain and text/html.
        part1 = MIMEText(text, 'plain')
        part2 = MIMEText(html, 'html')
        # Create message container - the correct MIME type is multipart/alternative.
        msg = MIMEMultipart('alternative')
        msg['Subject'] = subject
        msg['From'] = from_
        msg['To'] = to

        # Attach parts into message container.
        # According to RFC 2046, the last part of a multipart message, in this case
        # the HTML message, is best and preferred.
        msg.attach(part1)
        msg.attach(part2)

        conn = SMTP(smtp_server)
        conn.set_debuglevel(False)
        conn.login(username, password)
        try:
            conn.sendmail(from_, to, msg.as_string())
        finally:
            conn.close()

    #except Exception, exc:
    #    sys.exit( "mail failed; %s" % str(exc) ) # give a error message
    except:
        return False

    conn = imaplib.IMAP4(smtp_server, port = 143)
    # Python 3.5
    #context = ssl.create_default_context()
    #conn.starttls(context=context)
    conn.starttls()
    r = conn.login(username, password)
    if r[0] != 'OK':
        return False
    r = conn.select('INBOX.Sent')
    if r[0] != 'OK':
        return False
    r = conn.append('INBOX.Sent', '', imaplib.Time2Internaldate(time.time()), msg.as_string().encode('utf-8'))
    if r[0] != 'OK':
        return False
        
    return True
开发者ID:Eibriel,项目名称:hovyu-community-server,代码行数:48,代码来源:mail_client.py

示例2: POP3_SSL

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import select [as 别名]
        print '    error: server unexpectedly disconnected... try again'
else:
    print '    error: SMTP_SSL requires 2.6.3+'

# POP
print '*** Doing POP recv...'
try:
    s = POP3_SSL('pop.mail.yahoo.com', 995)
    s.user(MAILBOX)
    s.pass_(PASSWD)
    rv, msg, sz = s.retr(s.stat()[0])
    s.quit()
    line = getSubject(msg)
    print '    Received msg via POP: %r' % line
except error_proto:
    print '    error: POP for Yahoo!Mail Plus subscribers only'

# IMAP
print '*** Doing IMAP recv...'
try:
    s = IMAP4_SSL('imap.n.mail.yahoo.com', 993)
    s.login(MAILBOX, PASSWD)
    rsp, msgs = s.select('INBOX', True)
    rsp, data = s.fetch(msgs[0], '(RFC822)')
    line = getSubject(StringIO(data[0][1]))
    s.close()
    s.logout()
    print '    Received msg via IMAP: %r' % line
except error:
    print '    error: IMAP for Yahoo!Mail Plus subscribers only'
开发者ID:fjrti,项目名称:snippets,代码行数:32,代码来源:ymail.py


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