예제 #1
0
    def post(self, user):
        posted_data = request.get_json()
        title = posted_data["title"]
        seller_id = posted_data["seller_id"]
        content = posted_data["content"]
        furniture_id = posted_data["furniture_id"]

        buyer_id = str(user['_id'])
        buyer_email = user['email']
        buyer_username = user['username']

        furniture = find_furniture_by_id(furniture_id)
        if furniture is None:
            return jsonify({
                "status": 319,
                "msg": "Can not find the furniture"
            })
        furniture_name = furniture["furniture_name"]

        seller = find_user_by_id(seller_id)
        if seller is None:
            return jsonify({"status": 312, "msg": "User doesn't exist"})
        seller_email = seller["email"]
        seller_username = seller["username"]

        contact_form = add_contact_form({
            "buyer": buyer_id,
            "buyer_username": buyer_username,
            "seller": seller_id,
            "buyer_email": buyer_email,
            "furniture": furniture_id,
            "content": content,
            "title": title,
            "furniture_name": furniture_name
        })

        msg = Message(title,
                      recipients=[seller_email],
                      html=render_template(
                          'contact_email.html',
                          seller_username=seller_username,
                          buyer_username=buyer_username,
                          buyer_email="mailto:" + buyer_email,
                          furniture_name=furniture_name,
                          detail_link=current_app.config['FRONTEND_DOMAIN'] +
                          "message/" + str(contact_form.inserted_id)),
                      sender=('Furnitrade',
                              current_app.config['MAIL_USERNAME']))
        mail.send(msg)

        return jsonify({
            "status": 200,
            "msg": "Contact messge successfully send",
            "contact_form_id": str(contact_form.inserted_id)
        })
예제 #2
0
def notify(id_prescription):
    prescr = Ricetta.query.filter_by(id_ricetta=id_prescription).first()
    p = Persona.query.filter_by(id_persona=prescr.id_paziente).first()
    try:
        msg = Message('healthsystem',recipients=[p.email.indirizzo])
        msg.body = "Hello from %s" %  prescr.medico.persona.nome + \
                    " %s " % prescr.medico.persona.cognome + \
                    "a new prescription is "  + \
                    "available in our office %s" % \
                    prescr.medico.stud_leg.indirizzo.strada + \
                    ", %s " % prescr.medico.stud_leg.indirizzo.cap + \
                    "since %s " % prescr.data_emissione + ". %s ." % prescr.campo
        mail.send(msg)
    except Exception as e:
        raise e
    return redirect(request.args.get('next') or url_for('info', p_username=p.username))
예제 #3
0
def register():
    if request.method == 'POST':
        data = request.get_json()
        fname = data.get('first_name', None)
        lname = data.get('last_name', None)
        email = data.get('email', None)
        phone = data.get('phone', None)
        password = data.get('password', None)

        error = None
        if not fname:
            error = 'First name is required.'
        elif not lname:
            error = 'Last name is required.'
        elif not email:
            error = 'Email is required.'
        elif not password:
            error = 'Password is required.'
        elif dao.get_user_id_by_email(email) is not None:
            error = 'Email {} has already registered.'.format(email)
        elif dao.get_user_id_by_phone(phone) is not None:
            error = 'Phone {} has already registered.'.format(phone)

        if error:
            abort(403, error)

        msg = Message('Confirm Email',
                      sender='*****@*****.**',
                      recipients=[email])
        s = URLSafeTimedSerializer(current_app.config['SECRET_KEY'])
        token = s.dumps(email, salt='email-confirm')
        link = url_for('.confirm_email', token=token, _external=True)
        msg.body = 'Your link is {}'.format(link)
        mail.send(msg)
        print('email sending...')

        dao.add_user(fname, lname, email, phone, password)
        return 'success'

    return 'Register Page'
예제 #4
0
파일: email.py 프로젝트: Bright1992/blog
def send_email(subject,sender,recipients,text_body,html_body):
    msg=Message(subject,sender=sender,recipients=recipients)
    msg.body=text_body
    msg.html=html_body
    mail.send(msg)
예제 #5
0
파일: email.py 프로젝트: weijiayun/blog
def send_email(subject, sender, recipients, text_body, html_body):
    msg = Message(subject, sender=sender, recipients=recipients)
    msg.body = text_body
    msg.html = html_body
    mail.send(msg)
예제 #6
0
def send_async_email(app, msg):
    with app.app_context():
        mail.send(msg)