def Mail(emails, cc, msg): sub = status + ": " + msg['主题'] build_direction = "LEFT_TO_RIGHT" table_attributes = {"style": "width:100%", "border": "1"} #table_attributes = {"style": "width:100%;border:1px solid #000;", "border": "1"} html = convert(msg, build_direction=build_direction, table_attributes=table_attributes) pre = "详情请登录 <a href=\"" + dashhome + "\">" + dashhome + "</a><br/><hr>" suffix = "<hr><br><br><hr><b>智能云平台 运维组</b><br>主页: <a href=\"" + home + "\">" + home + "<br><hr><br>" html = pre + html + suffix send_mail(emails, cc, sub, html, 1)
def status(data): for task in data['tasks']: status = http_handler(task['address']) if status != task['status'] and status == '在线': task['status'] = status with open('server.json', 'w', encoding='utf-8') as f: json.dump(data, f) if status != task['status'] and status == '异常': task['status'] = status with open('server.json', 'w', encoding='utf-8') as f: json.dump(data, f) send_mail(app, task['owner'], task['address']) return data
def _handle_schedule(schedule_id): schedule = Schedule.get(Schedule.id == schedule_id) if not schedule: logger.warn("Schedule is invalid. ID = %s" % schedule_id) return to_mails = schedule.recipients.split(",") attachments = Attachment.gets_by_schedule(schedule_id) atta_dicts = [a.to_mandrill_dict() for a in attachments] rs = send_mail( subject=schedule.subject, from_mail=SEND_ADDRESS, to_mails=to_mails, html=schedule.content, attachments=atta_dicts, ) if not rs: logger.warn("Schedule send fail. ID = %s" % schedule_id) schedule.fail() return if schedule.repeat_strategy: schedule.wait(schedule.repeat_strategy.get_next_time()) else: schedule.send() for r in rs: logger.info(r) now = datetime.utcnow() History.create( recipient=r.get("email"), send_id=r.get("_id", ""), schedule_id=schedule.id, status=r.get("status"), reason=r.get("reject_reason") or "", send_time=now, update_time=now, )