Ejemplo n.º 1
0
def push():
    data = request.json
    to_email = data.get('email')
    file_ids = data.get('fileIds')
    if to_email is None or file_ids is None:
        return json.dumps({
            'code': -1,
            'msg': 'Email and File ids are required.'
        })
    # send emails
    files = [read_file(file_id) for file_id in file_ids]
    try:
        job = send_mail.queue(to_email, current_app.config['MG_EMAIL_FROM'],
                              current_app.config['MG_EMAIL_SUBJECT'],
                              current_app.config['MG_EMAIL_TEXT'], files,
                              current_app.config['MG_DOMAIN_NAME'],
                              current_app.config['MG_API_KEY'])
        # for file_id in file_ids:
        #     remove_file(file_id)
        return json.dumps({'code': 0, 'data': job.id})
    except requests.exceptions.RequestException as e:
        print(str(e))
        return json.dumps({
            'code': -1,
            'msg': 'Failed to send emails. Please try again.'
        })
Ejemplo n.º 2
0
def push():
    data = request.json
    to_email = data.get("email")
    file_ids = data.get("fileIds")
    if to_email is None or file_ids is None:
        return json.dumps({
            "code": -1,
            "msg": "Email and File ids are required."
        })
    # send emails
    files = [read_file(file_id) for file_id in file_ids]
    try:
        for file in files:
            file = [file]
            send_mail_using_yandex(to_email,
                                   current_app.config["YD_EMAIL_FROM"],
                                   current_app.config["YD_EMAIL_SUBJECT"],
                                   current_app.config["YD_EMAIL_TEXT"], file,
                                   current_app.config["YD_DOMAIN_NAME"],
                                   current_app.config["YD_APP_PWD"])
        return json.dumps({"code": 0})
    except requests.exceptions.RequestException as e:
        print(str(e))
        return json.dumps({
            "code": -1,
            "msg": "Failed to send emails. Please try again."
        })
    except SMTPDataError as e1:
        print(str(e1))
        return json.dumps({"code": -2, "msg": "File too large."})
Ejemplo n.º 3
0
def push():
    data = request.json
    to_email = data.get('email')
    file_ids = data.get('fileIds')
    if to_email is None or file_ids is None:
        return json.dumps({
            'code': -1,
            'msg': 'Email and File ids are required.'
        })
    # send emails
    files = [read_file(file_id) for file_id in file_ids]
    try:
        send_mail(to_email, files)
        for file_id in file_ids:
            remove_file(file_id)
        return json.dumps({'code': 0, 'data': file_ids})
    except requests.exceptions.RequestException as e:
        print(str(e))
        return json.dumps({
            'code': -1,
            'msg': 'Failed to send emails. Please try again.'
        })