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


Python SMTP.send_message方法代码示例

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


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

示例1: EmailNotifier

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import send_message [as 别名]
class EmailNotifier(BaseNotifier):
    regex = re.compile('^(?:mailto:)?([^:@\s][email protected][^:@\s]+)$')

    def __init__(self, config):
        self.config = config
        self.smtp = SMTP(config['smtp_server'])
        context = ssl.create_default_context()
        self.smtp.starttls(context=context)
        self.smtp.ehlo()
        self.smtp.login(
            self.config['smtp_username'],
            self.config['smtp_password']
        )

    def notify(self, contact, node):
        receipient = self.regex.match(contact).group(1)
        msg = MIMEText(
            node.format_infotext(self.config['text']),
            _charset='utf-8'
        )
        msg['Subject'] = '[Nodewatcher] %s offline' % node.name
        msg['From'] = self.config['from']
        msg['To'] = receipient

        self.smtp.send_message(msg)
        return True

    def quit(self):
        self.smtp.quit()
开发者ID:freifunk-kiel,项目名称:nodewatcher,代码行数:31,代码来源:Notifier.py

示例2: flush

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import send_message [as 别名]
 def flush(self):
      # Add extra newline to info() messages for separation in logfile
      if not self.buffer:
           _logger.info("No warnings, no email to send\n")
           return
      _logger.info(f"Sending logging email with {len(self.buffer)} records\n")
      txt = ''.join(self.format(record)+'\n' for record in self.buffer)
      msg = EmailMessage()
      msg['Subject'] = "mfaliquot: {}.py has something to say".format(self.scriptname)
      msg['To'] = ', '.join(self.to_addrs)
      msg['From'] = self.from_addr
      msg.set_content("Something went wrong (?) while {}.py was running:\n\n".format(self.scriptname)+txt)
      try:
           s = SMTP()
           s.connect(self.host, self.port)
           s.starttls()
           if self.username and self.password:
                s.login(self.username, self.password)
           s.send_message(msg)
           s.quit()
      except SMTPException as e:
           _logger.exception("Logging email failed to send:", exc_info=e, extra=self._special_kwarg)
      except OSError as e:
           _logger.exception("Some sort of smtp problem:", exc_info=e, extra=self._special_kwarg)
      except BaseException as e:
           _logger.exception("Unknown error while attempting to email:", exc_info=e, extra=self._special_kwarg)
      else:
           self.buffer.clear()
开发者ID:dubslow,项目名称:MersenneForumAliquot,代码行数:30,代码来源:__init__.py

示例3: main

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import send_message [as 别名]
def main(smtp_data, email_data, address):
    """
    Main function
    """
    month = datetime.now().month # Loading the current month
    text = """<p>Olá,<br>
    Vocês poderiam me enviar o boleto do aluguel do mês atual, com vencimento
    no próximo dia 10?
    Meu imóvel é o da <b>{address}</b></p>
    <p>Obrigado!</p>
    """
    subject = "Boleto de aluguel do mês {month}"

    message = MIMEText(text.format(address=address), 'html')
    message['Subject'] = subject.format(month=month)
    message['From'] = email_data['sender']
    message['To'] = email_data['receiver']
    message['Reply-To'] = email_data['reply_to']

    server = SMTP(host=smtp_data['server'], port=smtp_data['port'])
    server.ehlo()
    server.starttls()
    server.login(smtp_data['username'], smtp_data['password'])
    server.send_message(message)
    server.close()
开发者ID:fbidu,项目名称:gmailBots,代码行数:27,代码来源:imobiliaria.py

示例4: _sentMail

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import send_message [as 别名]
 def _sentMail(self):
     if self.notice:
         auth = {user:'','password':''}
         smtp = SMTP()
         try:
             smtp.login(auth)
         except:
             smtp.close()
             return
         smtp.send_message(msg)
         smtp.close()
开发者ID:hufuyu,项目名称:s_kits,代码行数:13,代码来源:chk_wooyun_rss.py

示例5: send_mail_msg

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import send_message [as 别名]
def send_mail_msg(to, subject, msg):
    msg['Subject'] = subject
    msg['From'] = config_email_user
    msg['To'] = to

    # Send the message via our own SMTP server.
    s = SMTP(config_email_server, config_email_port)
    s.ehlo()
    s.starttls()
    s.ehlo
    s.login(config_email_user, config_email_password)
    s.send_message(msg)
    s.quit()
开发者ID:scanlom,项目名称:Kumamon,代码行数:15,代码来源:api_mail.py

示例6: send_message

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import send_message [as 别名]
  def send_message(self, message):
    '''
    Sends the actual message.
    '''
    logging.info('Sending message')

    smtp = SMTP()
    smtp.connect(self.settings['host'], self.settings['port'])
    smtp.ehlo()
    smtp.starttls()
    smtp.login(self.settings['username'], self.settings['password'])
    smtp.send_message(message)
    smtp.quit()
开发者ID:ollie,项目名称:usd-rate-notifier-python,代码行数:15,代码来源:notifier.py

示例7: send_error

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import send_message [as 别名]
def send_error(ex, config):
    body = 'Error type: ' + type(ex).__name__ + '\nMessage: '
    for arg in ex.args:
        body += arg + '\n'
    msg = MIMEText(body)
    msg['Subject'] = 'name.com Update Error'
    msg['From'] = 'donotreply'
    msg['To'] = config['email']

    server = SMTP(config['smtp'])
    server.ehlo_or_helo_if_needed()
    server.starttls()
    server.login(config['smtpuser'], config['smtppassword'])
    server.send_message(msg)
    server.quit()
开发者ID:davidalk,项目名称:dnsrecord-update,代码行数:17,代码来源:dnsrec_update.py

示例8: test_email

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import send_message [as 别名]
def test_email(email_config):

    subject = "Héèéè"
    message_content = "Contentééééééé\r\nhûhûhhû\r\n"
    msg = MIMEText(message_content.encode('utf-8'), 'plain', 'utf-8')
    msg['Subject'] = Header(subject, 'utf-8')
    msg['From'] = email_config["from_address"]
    msg['To'] = email_config["to_test_address"]


    smtp = SMTP(email_config["smtp_server"])
    try:
        smtp.set_debuglevel(True)
        print("\rdbg smtp.noop()")
        print(smtp.noop())

        print("\rdbg smtp.starttls()")
        print(smtp.starttls())

        print("\rdbg smtp.login()")
        print(smtp.login(email_config["from_username"], email_config["from_password"]))

        print("\rdbg smtp.send_message()")
        print(smtp.send_message(msg))
    except Exception as inst:
        print(inst)

    print("\rdbg smtp.quit()")
    print(smtp.quit())
开发者ID:vaillancourt,项目名称:christmas,代码行数:31,代码来源:pick.py

示例9: send_mail

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import send_message [as 别名]
def send_mail(smtp_host, smtp_port, smtp_timeout, smtp_username, \
        smtp_password, recipient, subject, message):
    from email.mime.text import MIMEText
    from smtplib import SMTP
    smtp = None
    try:
        smtp = SMTP(host=smtp_host, port=smtp_port, timeout=smtp_timeout)
        smtp.starttls()
        smtp.login(smtp_username, smtp_password)
        message = MIMEText(message)
        message['From'] = smtp_username
        message['Subject'] = subject
        message['To'] = recipient
        smtp.send_message(message)
    finally:
        if smtp:
            smtp.quit()
开发者ID:aandeers,项目名称:dynipmonitor,代码行数:19,代码来源:dynipmonitor.py

示例10: send_mail

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import send_message [as 别名]
def send_mail(server: smtplib.SMTP, me: str, recipient: str, name: str, subject: str, template: str):
    try:
        text = template.replace("%name%", name).replace("%email%", recipient)

        msg = MIMEMultipart('alternative')
        # TODO: add name tag
        msg['Subject'] = subject
        msg['From'] = me
        msg['To'] = recipient

        content = MIMEText(text, "html")
        msg.attach(content)
        # TODO: ADD PLAIN MESSAGE
        # msg.attach(MIMEText(plain, "plain"))

        server.send_message(me, recipient, msg.as_string())
        return True
    except smtplib.SMTPRecipientsRefused:
        logger.warn("Recipient refused")
        return False
开发者ID:games647,项目名称:Balanced-Mass-Emailer,代码行数:22,代码来源:mass-emailer.py

示例11: send_message

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import send_message [as 别名]
def send_message(body, target):
    with open('config.json', 'r') as f:
        email_config = json.load(f)['email']
        server = SMTP(email_config['server'], email_config['port'])
        my_addr = email_config['user']
        pswd = email_config['password']

    # Log in to the server
    server.ehlo()
    server.starttls()
    server.ehlo()
    server.login(my_addr, pswd)

    msg = MIMEMultipart('alternative')
    msg['Subject'] = 'TextReminder'
    msg['From'] = my_addr
    msg['To'] = target
    msg.attach(MIMEText(body))
    server.send_message(msg)
    server.quit()
开发者ID:sfall,项目名称:textreminder,代码行数:22,代码来源:textreminder.py

示例12: sendMail

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import send_message [as 别名]
def sendMail(checkin_num=-1, message=''):
    '''Send mail'''

    me = mail_config['from']
    to = mail_config['to']
    passwd = mail_config['passwd']
    smtp_server = mail_config['smtp_server']
    smtp_port = mail_config['smtp_port']

    if (len(message) == 0):
        message = OK_message
    msg = MIMEText(message)

    msg['Subject'] = 'SMZDM 连续签到 %s 天' % str(checkin_num)
    msg['From'] = me
    msg['To'] = to

    s = SMTP(smtp_server, smtp_port)
    s.starttls()
    s.login(me, passwd)
    s.send_message(msg)
    s.quit()
开发者ID:ppproxy,项目名称:SMZDMCheck-In,代码行数:24,代码来源:smzdm_checkin.py

示例13: send_message

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import send_message [as 别名]
def send_message(request):
    # Format message for HTML
    body = request.POST['message'].replace('\n', '<br>')

    # Build message
    message = """
    <html>
        <p>{body}</p>
    </html>
    """.format(name=request.POST['name'], email=request.POST['email'], body=body)

    # Build email
    msg = MIMEText(message, 'html')
    msg['Subject'] = request.POST['subject']
    msg['Reply-To'] = request.POST['email']
    msg['To'] = settings.EMAIL
    msg['From'] = '{name} <[email protected]{host}>'.format(
        name=request.POST['name'],
        host=request.get_host().replace('www.', ''))

    # Send email
    smtp = SMTP('localhost')
    smtp.send_message(msg)
    smtp.quit()
开发者ID:jaminthorns,项目名称:portfolio-website,代码行数:26,代码来源:views.py

示例14: send_a_mail

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import send_message [as 别名]
def send_a_mail(email_config, dest_name, dest_adress, picked_name, dry_run):
    subject = "La Pige de Noël"
    message_content = dest_name + "!\r\nLa personne que tu as pigée pour l'échange de cadeau de Noël est : \r\n" + picked_name
    msg = MIMEText(message_content.encode('utf-8'), 'plain', 'utf-8')
    msg['Subject'] = Header(subject, 'utf-8')
    msg['From'] = email_config["from_address"]
    msg['To'] = dest_adress

    if dry_run:
        print(msg.as_string())
        return

    smtp = SMTP(email_config["smtp_server"])
    try:
        smtp.set_debuglevel(True)
        smtp.noop()
        smtp.starttls()
        smtp.login(email_config["from_username"], email_config["from_password"])
        smtp.send_message(msg)

    except Exception as inst:
        print(inst)

    smtp.quit()
开发者ID:vaillancourt,项目名称:christmas,代码行数:26,代码来源:pick.py

示例15: run

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import send_message [as 别名]

#.........这里部分代码省略.........
                EM = 1
                if m:
                    EY = int(m.group(1))
                    EM = int(m.group(2))
                ctx = urlopen("%s%s/%s" % (source, ml, mboxfile ))
                inp = ctx.read().decode(ctx.headers.get_content_charset() or 'utf-8', errors='ignore')
    
                tmpname = hashlib.sha224(("%f-%f-%s-%s.mbox" % (random.random(), time.time(), ml, mboxfile)).encode('utf-8') ).hexdigest()
                with open(tmpname, "w") as f:
                    f.write(inp)
                    f.close()
                messages = mailbox.mbox(tmpname)

            count = 0
            bad = 0
            LEY = EY
            
            
            for message in messages:
                # If --filter is set, discard any messages not matching by continuing to next email
                if fromFilter and 'from' in message and message['from'].find(fromFilter) == -1:
                    continue
                if resendTo:
                    self.printid("Delivering message %s via MTA" % message['message-id'] if 'message-id' in message else '??')
                    s = SMTP('localhost')
                    try:
                        if list_override:
                            message.replace_header('List-ID', list_override)
                        message.replace_header('To', resendTo)
                    except:
                        if list_override:
                            message['List-ID'] = list_override
                    message['cc'] = None
                    s.send_message(message, from_addr=None, to_addrs=(resendTo))
                    continue
                if (time.time() - stime > timeout): # break out after N seconds, it shouldn't take this long..!
                    self.printid("Whoa, this is taking way too long, ignoring %s for now" % tmpname)
                    break

                json, contents = archie.compute_updates(list_override, private, message)
                
                if json and not (json['list'] and json['list_raw']):
                    self.printid("No list id found for %s " % json['message-id'])
                    bad += 1
                    continue

                # If --dedup is active, try to filter out any messages that already exist
                if json and dedup and message.get('message-id', None):
                    res = es.search(
                        index=dbname,
                        doc_type="mbox",
                        size = 1,
                        body = {
                            'query': {
                                'bool': {
                                    'must': [
                                        {
                                            'term': {
                                                'message-id': message.get('message-id', None)
                                            }
                                        }
                                    ]
                                }
                            }
                        }
                    )
开发者ID:jimjag,项目名称:ponymail,代码行数:70,代码来源:import-mbox.py


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