コード例 #1
0
def send_message():
    form = EmailForm(request.form)
    if form.validate():
        app.config.from_object('email_conf.Config')
        mail = Mail(app)
        msg = Message(sender=current_app.config['MAIL_USERNAME'],
                      recipients=[current_app.config['MAIL_USERNAME']],
                      subject=f'message from {form.name.data} through website')
        mail.body = form.message.data
        msg.html = f'{form.email_field.data}<br>{mail.body}'
        mail.send(msg)
        flash('Message sent', 'success')
        return render_template('home.html',
                               form=form,
                               mail=current_app.config['MAIL_USERNAME'],
                               nnet_library=nnet_library,
                               library_link=library_links[nnet_library],
                               name=model_name,
                               link=model_links[model_name])

    flash('There was an error sending the message', 'error')
    return render_template('home.html',
                           form=form,
                           mail=current_app.config['MAIL_USERNAME'],
                           nnet_library=nnet_library,
                           library_link=library_links[nnet_library],
                           name=model_name,
                           link=model_links[model_name])
コード例 #2
0
ファイル: main.py プロジェクト: CozyDoomer/personal-website
def send_message():
    form = EmailForm(request.form)
    if form.validate():
        app.config.from_object('email_conf.Config')
        mail = Mail(app)
        msg = Message(sender=current_app.config['MAIL_USERNAME'],
                      recipients=[current_app.config['MAIL_USERNAME']],
                      subject=f'message from {form.name.data} through website')
        mail.body = form.message.data
        msg.html = f'{form.email.data}<br>{mail.body}'
        mail.send(msg)
        return jsonify({'status': 'success'})
    print('error while sending email')
    return jsonify({'status': 'error'})