Exemple #1
0
def sendmail(to, from_, subject, msg):
    s = smtp_connect()
    if len(msg) > 5 * 1024**2:
        msg = msg[:1024**2] + '\n\n日志过长,省略ing……\n\n' + msg[-1024**2:]
    msg = assemble_mail('[%s] %s' % (MAILTAG, subject), to, from_, text=msg)
    s.send_message(msg)
    s.quit()
Exemple #2
0
  def sendmail(self, to: Union[str, List[str]],
               subject: str, msg: str) -> None:
    if not self.send_email:
      return

    s = self.smtp_connect()
    if len(msg) > 5 * 1024 ** 2:
      msg = msg[:1024 ** 2] + '\n\n日志过长,省略ing……\n\n' + \
          msg[-1024 ** 2:]
    mail = assemble_mail('[%s] %s' % (
      self.mailtag, subject), to, self.from_, text=msg)
    s.send_message(mail)
    s.quit()
Exemple #3
0
    def sendmail(self, to, subject, msg):
        if not self.send_email:
            return

        s = self.smtp_connect()
        if len(msg) > 5 * 1024**2:
            msg = msg[:1024 ** 2] + '\n\n日志过长,省略ing……\n\n' + \
                msg[-1024 ** 2:]
        msg = assemble_mail('[%s] %s' % (self.mailtag, subject),
                            to,
                            self.from_,
                            text=msg)
        s.send_message(msg)
        s.quit()
Exemple #4
0
    def emit(self, record: logging.LogRecord) -> None:
        self.deque.append(record)

        t = time.time()
        if t <= self.last_mail_time + self.min_gap_seconds:
            return

        subject, body = self.format_as_mail(self.deque)
        try:
            mail = assemble_mail(
                f'[{self.tag}] {subject}',
                self.toaddrs,
                self.fromaddr,
                text=body,
            )
            sendmail(mail)
            self.deque.clear()
            self.last_mail_time = t
        except Exception:
            self.handleError(record)
Exemple #5
0
             logger.info('Creating user %s on server %s ...' %
                         (username, server))
             subject = '%s 上的用户 %s 创建成功!' % (server, username)
             create_user(username, server)
         passwd = str(uuid.uuid1()).replace('-', '')
         logger.info(
             'Setting password for user %s on server %s ...' %
             (username, server))
         reset_password(username, server, passwd)
         message = ['密码为 %s' % passwd, get_ip(server)]
         message = '\n\n'.join(message)
         logger.info('Sending email to %s ...' % sender)
         smtp.login(IMAPConfig.account, IMAPConfig.password)
         smtp.send_message(
             assemble_mail(subject,
                           sender,
                           IMAPConfig.account,
                           text=message))
         smtp.quit()
 except Exception as e:
     message = [str(data), traceback.print_exc()]
     message = '\n\n'.join(message)
     smtp.login(IMAPConfig.account, IMAPConfig.password)
     smtp.send_message(
         assemble_mail('mailbot 爆炸啦',
                       '*****@*****.**',
                       IMAPConfig.account,
                       text=message))
     smtp.quit()
 finally:
     result = imap.copy(num, '&XfJSIJZk-')
     if result[0] == 'OK':
Exemple #6
0
def sendmail(to, from_, subject, msg):
  s = smtplib.SMTP()
  s.connect()
  msg = assemble_mail(subject, to, from_, text=msg)
  s.send_message(msg)
  s.quit()