def send_async_email(msg, html, text, attach=None, send_independently=True): """ 发送email :param subject: :param recipients:数组 :param text: :param html: :param attach:(<filename>,<content_type>) :param send_independently:如果为True, 独立给recipients中的每个地址发送信息, 否则,一次发送, 收件人能看到其他收件人的邮箱 :return: """ # 检测插件 data = plugin_manager.call_plug(hook_name="send_email", send_independently=send_independently, msg=msg, html=html, text=text, attach=attach) if data == "__no_plugin__": with app.app_context(): msg_obj = Message(subject=msg["subject"], html=html) if send_independently: # 独立发送, 先连接好邮件服务器 with mail.connect() as conn: for recipient in msg["recipients"]: msg_obj.recipients = [recipient] send_email_process(msg_obj, conn) else: msg_obj.recipients = msg["recipients"] return send_email_process(msg_obj)
def send_async_email(msg, html, text, attach=None, send_independently=True, ctype="other"): """ 发送email :param subject: :param recipients:数组 :param text: :param html: :param attach:(<filename>,<content_type>) :param send_independently:如果为True, 独立给recipients中的每个地址发送信息, 否则,一次发送, 收件人能看到其他收件人的邮箱 :return: """ # 检测插件 data = plugin_manager.call_plug(hook_name="send_email", send_independently=send_independently, msg=msg, html=html, text=text, attach=attach) if data == "__no_plugin__": with app.app_context(): msg_obj = Message(subject=msg["subject"], html=html) if send_independently: # 独立发送, 先连接好邮件服务器 with mail.connect() as conn: for recipient in msg["recipients"]: msg_obj.recipients = [recipient] status, result_msg = send_email_process(msg_obj, conn) else: msg_obj.recipients = msg["recipients"] status, result_msg = send_email_process(msg_obj) log = { "type": "email", "error_info": result_msg, 'status': status, 'subject': msg_obj.subject, 'from': msg_obj.sender, 'to': list(msg["recipients"]), 'date': msg_obj.date, 'body': msg_obj.body, 'html': msg_obj.html, 'msgid': msg_obj.msgId, 'time': time.time(), 'msg_type': ctype } mdbs["sys"].db.sys_message.insert_one(log)
def send_async_email(app, msg, recipients, send_independently=True): """ 异步发送email :param app: :param msg: :param send_independently: 每个单独发送 :return: """ mdbs["sys"].init_app(reinit=True) with app.app_context(): if send_independently: # 独立发送, 先连接好邮件服务器 with mail.connect() as conn: for recipient in recipients: msg.recipients = [recipient] send_email_process(msg, conn) else: msg.recipients = recipients return send_email_process(msg)