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


Python SMTP_SSL.close方法代码示例

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


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

示例1: SendMail

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import close [as 别名]
    def SendMail(self):
        USERNAME = "[email protected]"
        PASSWORD = "YOURPASSWORD"
        SMTPserver = 'smtp.YOURMAIL.com'

        for permalink in self.commentswithtext:
            body = self.commentswithtext[permalink]
            if body[:len(self.breakstring)] != self.breakstring:
                content = "FYI - " + permalink + """
                """ + self.commentswithtext[permalink] + """

                Thanks!
                """
                content = content.encode('utf-8')
                text_subtype = 'plain'
                msg = MIMEText(content,'plain','utf-8')
                msg['Subject']=  "New Reddit Comment"
                msg['From']   = "[email protected]" 

                conn = SMTP(SMTPserver)
                conn.set_debuglevel(False)
                conn.login(USERNAME, PASSWORD)
                try:
                    print("Sending Mail -- " + permalink)
                    conn.sendmail(msg['From'],msg['From'], msg.as_string())
                finally:
                    conn.close()     

                # Mark that we've now sent this message      
                self.commentswithtext[permalink] = self.breakstring + str(   int(time.time())   )
开发者ID:e1ven,项目名称:WatchReddit,代码行数:32,代码来源:watchreddit.py

示例2: SendingEmail

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import close [as 别名]
def SendingEmail(email,password,message,date):
    SMTPserver = 'smtp.gmail.com'
    sender = email
    receivers = ['[email protected]','[email protected]']    
    
    # typical values for text_subtype are plain, html, xml
    text_subtype = 'plain'
        
    content = message
    
    subject="Bluetooth Data Daily Report: %s" % (date)
    
    USERNAME = email
    PASSWORD = password
    
    try:
        msg = MIMEText(content, text_subtype)
        msg['Subject']= subject
        msg['From'] = sender # some SMTP servers will do this automatically, not all
    
        conn = SMTP(SMTPserver)
        conn.set_debuglevel(False)
        conn.login(USERNAME, PASSWORD)
        try:
            conn.sendmail(sender, receivers, msg.as_string())
        finally:
            conn.close()
    
    except Exception, exc:
        sys.exit( "mail failed; %s" % str(exc) ) # give a error message
开发者ID:mingchen7,项目名称:BlueTIME,代码行数:32,代码来源:SendingDailyReport.py

示例3: send_email

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import close [as 别名]
def send_email(content):
    if content == "":
        return False

    destination = [DESTINATION]

    # typical values for text_subtype are plain, html, xml
    text_subtype = 'plain'

    from smtplib import SMTP_SSL as SMTP       # this invokes the secure SMTP protocol (port 465, uses SSL)
    from email.mime.text import MIMEText

    try:
        msg = MIMEText(content, text_subtype, "utf-8")
        msg['Subject'] = SUBJECT_EMAIL
        msg['From'] = YA_USER
        msg['To'] = DESTINATION
        conn = SMTP(SMTP_SERVER)
        conn.set_debuglevel(False)
        conn.login(YA_USER, YA_PASS)

        stat = False

        try:
            conn.sendmail(YA_USER, destination, msg.as_string())
            stat = True
        finally:
            conn.close()
    except Exception, exc:
        pass
开发者ID:AntonMezhanskiy,项目名称:backuper1c,代码行数:32,代码来源:app.py

示例4: send_token

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import close [as 别名]
def send_token(token, address, server, username, password):

    content =  "Dein Token fuer den Zugang zum OpenLab ist da:\n\n"
    content += "\t" + token + "\n\n"
    content += "Nutze diese Links:\n"
    content += "- Tuer oeffnen: https://labctl.ffa/sphincter/?action=open&token=" + token + "\n"
    content += "- Tuer schliessen: https://labctl.ffa/sphincter/?action=close&token=" + token + "\n"
    content += "- Status abfragen: https://labctl.ffa/sphincter/?action=state"

    sender = '[email protected]'

    try:
        msg = MIMEText(content, 'plain')
        msg['Subject'] = 'Dein OpenLab-Zugang'
	msg['Date'] = strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())
        msg['From']    = sender

        conn = SMTP(server)
        conn.set_debuglevel(False)
        conn.login(username, password)
        try:
            conn.sendmail(sender, [address], msg.as_string())
        finally:
            conn.close()

    except Exception, exc:
        sys.exit( "mail failed; %s" % str(exc) )
开发者ID:devkral,项目名称:sphincter,代码行数:29,代码来源:gentoken.py

示例5: sendMail

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import close [as 别名]
def sendMail(RECIPIENT,SUBJECT,TEXT):
    import sys
    import os
    import re
    from smtplib import SMTP_SSL as SMTP       # this invokes the secure SMTP protocol (port 465, uses SSL)
    # from smtplib import SMTP                  # use this for standard SMTP protocol   (port 25, no encryption)
    from email.MIMEText import MIMEText
    SMTPserver = 'smtp.gmail.com'
    sender =     '[email protected]'
    destination = [RECIPIENT]

    USERNAME = "danbath"
    PASSWORD = "4Fxahil3"

    # typical values for text_subtype are plain, html, xml
    text_subtype = 'plain'

    
    try:
        msg = MIMEText(TEXT, text_subtype)
        msg['Subject']=       SUBJECT
        msg['From']   = sender # some SMTP servers will do this automatically, not all

        conn = SMTP(SMTPserver)
        conn.set_debuglevel(False)
        conn.login(USERNAME, PASSWORD)
        try:
            conn.sendmail(sender, destination, msg.as_string())
        finally:
            conn.close()
    
    except Exception, exc:
        sys.exit( "mail failed; %s" % str(exc) ) # give a error message
开发者ID:dbath,项目名称:wahnsinn,代码行数:35,代码来源:utilities.py

示例6: send_mail

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import close [as 别名]
def send_mail(receivers, subject, content, attachment=None, filename=None):
    msg = MIMEMultipart()
    msg['Subject'] = subject
    msg['From'] = config.FROM_EMAIL
    msg['To'] = receivers

    if config.DEV_ENV:
        msg['To'] = config.TEST_TO_EMAIL

    msg.preamble = 'Multipart message.\n'

    part = MIMEText(content)
    msg.attach(part)

    if attachment:
        part = MIMEApplication(open(attachment, "rb").read())
        part.add_header('Content-Disposition', 'attachment', filename=filename)
        msg.attach(part)

    mailer = SMTP_SSL(config.SMTP_SERVER, config.SMTP_PORT)
    # mailer.ehlo()
    # mailer.starttls()
    mailer.login(config.USERNAME, config.PASSWORD)
    mailer.set_debuglevel(1)
    mailer.sendmail(msg['From'], msg['To'].split(', '), msg.as_string())
    mailer.close()
开发者ID:ankitjain87,项目名称:anyclean,代码行数:28,代码来源:util.py

示例7: sendSMS

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import close [as 别名]
def sendSMS(tresc):
    text_subtype = "plain"  # plain, html, xml
    charset = "utf-8"  # utf-8 dla polskich znakow
    domena = ""
    usePrefix = False
    if config.siec == "plus":
        usePrefix = True
        domena = "@text.plusgsm.pl"
    elif config.siec == "orange":
        domena = "@sms.orange.pl"  # TODO: Tworzenie maila do wyslania smsm, moze cos lepszego niz if/elif?
    else:
        domena = "@text.plusgsm.pl"  # by nie bylo jakis nieporozumien

    try:
        msg = MIMEText(tresc, text_subtype, charset)
        msg["Subject"] = "Info"  # temat wiadomosci
        if usePrefix == True:
            msg["To"] += config.prefix

        msg["To"] += config.numer + domena  # TODO: konfiguracja serwera sms
        msg["From"] = config.emails[config.server][1][0]  # nawet nie dziala ale musi byc

        conn = SMTP_SSL("smtp." + config.emails[config.server][0], config.smtp_port)
        conn.login(config.emails[config.server][1][0], config.emails[config.server][1][1])
        try:
            conn.sendmail(config.emails[config.server][1][0], msg["To"], msg.as_string())
        finally:
            conn.close()
    except Exception, exc:
        ekg.command("gg:msg %s SMS Failed: %s" % (config.admin, str(exc)))  # give a error message
开发者ID:Huczu,项目名称:kerberon-pymailergg,代码行数:32,代码来源:mailer.py

示例8: send_mail

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import close [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

示例9: send_reminder_email

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import close [as 别名]
def send_reminder_email(content, to, subject):


    to = ['[email protected]', '[email protected]']
    text_subtype = 'plain'

    try:
        msg = MIMEText(content.encode('utf-8'), text_subtype)
        msg.set_charset('utf-8')

        msg['Subject']  = subject
        msg['From']     = smtp_conf['from']
        msg['To']       = ','.join(to)
        msg['Reply-To'] = smtp_conf['reply-to']

        conn = SMTP(smtp_conf['server'], 465)
        conn.set_debuglevel(False)
        conn.login(smtp_conf['user'], smtp_conf['pass'])
        try:
            conn.sendmail(smtp_conf['from'], to, msg.as_string())
        finally:
            conn.close()

    except Exception, exc:
        sys.exit( "mail failed; %s" % str(exc) ) # give a error message
开发者ID:rdalverny,项目名称:teamreport,代码行数:27,代码来源:reminder_email.py

示例10: create_validator

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import close [as 别名]
def create_validator(email):
	key = list(string.ascii_uppercase + string.ascii_lowercase + string.digits)
	random.shuffle(key)
	key = ''.join(key[:25])
	item = ValidationQueue(key=key, email=email)
	item.save()

	text = '''
	Hello,
		Please go to http://127.0.0.1:8000/b/confirm_account/''' + key + '''/ to validate your account.

		Validation will take up to a minute. Please do not interrupt the process by closing the tab.
	'''
	message = MIMEText(text, 'plain')
	message['Subject'] = 'Verify Account'
	to_address = email
	try:
		conn = SMTP('smtp.gmail.com')
		conn.set_debuglevel(True)
		conn.login(from_address, password)
		try:
			conn.sendmail(from_address, to_address, message.as_string())
		finally:
			conn.close()
	except Exception:
		print("Failed to send email")
开发者ID:chiranjeevjain,项目名称:bookmark-manager,代码行数:28,代码来源:helpers.py

示例11: run

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import close [as 别名]
    def run(self):

        if self.getSender() and \
           self.getRecipient() and \
           self.getSubject() and \
           self.getContent():

            try:
                message = MIMEText(self.getContent(), self.getTextSubtype())
                message['Subject'] = self.getSubject()
                message['From'] = self.getSender()

                connection = SMTP(self.getSmtpServer(), self.getPort())
                connection.set_debuglevel(False)
                connection.login(self.getUsername(), self.getPasswd())

                try:
                    connection.sendmail(self.getSender(),
                                        self.getRecipient(),
                                        message.as_string())
                finally:
                    connection.close()
            except Exception, e:
                print "Message to {0} failed: {1}".format(
                                                self.getRecipient(), e)
开发者ID:iamjohnnym,项目名称:RemoteSendMail,代码行数:27,代码来源:remotesendmail.py

示例12: sendEmail

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import close [as 别名]
def sendEmail(text):
    infoFp = open("Info.txt", "r")
    sender = infoFp.readline().rstrip('\n')
    password = infoFp.readline().rstrip('\n')
    username = infoFp.readline().rstrip('\n')
    
    SMTPserver = "smtp.gmail.com"
    destination = sender
    text_subtype = "plain"

    if text == "":
        print "You must supply valid text!"
        return
    else:
        content = text

    msg = MIMEText(content)
    msg['Subject'] = "IRC ALERT"
    msg['From'] = sender

    conn = SMTP(SMTPserver)
    conn.set_debuglevel(False)
    conn.login(username, password)
    conn.sendmail(sender, destination, msg.as_string())
    conn.close()
开发者ID:bl4ckdu5t,项目名称:AFK-IRC-bot,代码行数:27,代码来源:main.py

示例13: sendmail

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import close [as 别名]
def sendmail(to, app, attach0=False, attach1=False):

    from smtplib import SMTP_SSL as SMTP
    from email.MIMEText import MIMEText

    destination = [to]

    # read attach
    contentattach = ''
    if attach0 and not os.stat("%s" % attach0).st_size == 0: 
        fp = open(attach0,'rb')
        contentattach += '------------------ Error begin\n\n'
        contentattach += fp.read()
        contentattach += '\n------------------ Error end'
        fp.close()

    if attach1 and not os.stat("%s" % attach1).st_size == 0: 
        fp = open(attach1,'rb')
        contentattach += '\n\n------------------ Success begin\n\n'
        contentattach += fp.read()
        contentattach += '\n------------------ Success end'
        fp.close()

    msg = MIMEText(contentattach, 'plain')
    msg['Subject'] = "Mr.Script %s" % app
    msg['From'] = sender
                    
    try:
        conn = SMTP(smtpserver)
        conn.set_debuglevel(False)
        conn.login(username, password)
        conn.sendmail(sender, destination, msg.as_string())
        conn.close()
    except:
        print '    *** Error trying send a mail. Check settings.'
开发者ID:teagom,项目名称:mr-robot,代码行数:37,代码来源:external.py

示例14: send_via_gmail

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import close [as 别名]
def send_via_gmail(from_addr, to_addr, msg):
    print "send via SSL..."
    s = SMTP_SSL('smtp.gmail.com', 465)
    s.login(FROM_MAIL_ADDRESS, FROM_MAIL_PASSWORD)
    s.sendmail(from_addr, [to_addr], msg.as_string())
    s.close()
    print 'mail sent!'
开发者ID:junpei0029,项目名称:mynews,代码行数:9,代码来源:view.py

示例15: send_email

# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import close [as 别名]
    def send_email(self, from_address, to_addresses, cc_addresses, bcc_addresses, subject, body):
        """
        Send an email

        Args:
            to_addresses: must be a list
            cc_addresses: must be a list
            bcc_addresses: must be a list
        """
        try:
            # Note: need Python 2.6.3 or more
            conn = SMTP_SSL(self.smtp_host, self.smtp_port)
            conn.login(self.user, self.password)
            msg = MIMEText(body, 'plain', self.email_default_encoding)
            msg['Subject'] = Header(subject, self.email_default_encoding)
            msg['From'] = from_address
            msg['To'] = ', '.join(to_addresses)
            if cc_addresses:
                msg['CC'] = ', '.join(cc_addresses)
            if bcc_addresses:
                msg['BCC'] = ', '.join(bcc_addresses)
            msg['Date'] = Utils.formatdate(localtime=True)
            # TODO: Attached file
            conn.sendmail(from_address, to_addresses, msg.as_string())
        except:
            raise
        finally:
            conn.close()
开发者ID:ryuiso,项目名称:indeza,代码行数:30,代码来源:receive2.py


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