Exemple #1
0
def get_config(project, key):
    """
    获取网站动态配置中对应的project中key的值
    :return:
    """
    with app.app_context():
        return get_all_config()[project][key]
Exemple #2
0
def get_configs(project):
    """
    获取网站动态配置中对应的project
    :return:
    """
    with app.app_context():
        return get_all_config()[project]
Exemple #3
0
def get_plugin_config(plugin_name, key):
    """
    获取网站动态配置中对应的project中key的值
    :return:
    """
    with app.app_context():
        return get_all_config()[plugin_name][key]
Exemple #4
0
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)
Exemple #5
0
def get_plugin_configs(plugin_name):
    """
    获取网站动态配置中对应的project
    :return:
    """
    with app.app_context():
        return get_all_config()[plugin_name]
Exemple #6
0
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)
Exemple #7
0
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)
Exemple #8
0
def get_configs(project):
    with app.app_context():
        return get_all_config()[project]
Exemple #9
0
def get_config(project, key):
    with app.app_context():
        return get_all_config()[project][key]
Exemple #10
0
def createdb():
    with app.app_context():
        db.create_all()
Exemple #11
0
def createdb():
    with app.app_context():
        db.create_all()