Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
Allowing user to add details to flask-mail message

So I have a modal on my site from which I want my user to be able to enter their email, hit submit, and then the app to message me with the users email. So far I've got the site sending a message but I'm unsure how to get the users email into the message. Any help would be much appreciated.

My code for sending the email


@app.route('/sendmail/', methods=['POST','GET'])
def send_mail():
try:
#emaiil = request.form['email']
msg = Message("Access request",
sender="SENDING_EMAIL",
recipients=["MY_EMAIL"])
msg.body = "Users email is"
mail.send(msg)
flash('Request sent!')
return redirect(url_for('main'))
except Exception, e:
return(str(e))

My modal for which the user enters their email


<div class="modal-body">
<p>Password can be obtained from somewhere</p>
<form action="{% print url_for('send_mail') %}" class ="form- inline" method="post">
<input type = "email" class = "form-control" placeholder="Email" name = "email">
<a href="/sendmail" class ="btn btn-default">Submit</a>
<button type="button" class="btn btn-secondary" data- dismiss="modal modal2">Close</button>
</form>

The modal is called from here


@app.route("/", methods=['POST','GET'])
def main():
return render_template('main.html')

/r/flask
https://redd.it/8at9sg