I am trying to build a tool using Python, flask, flask-wtforms, and flask-mail where:
a) A user goes to a website and fills out a form
b) After a user fills out a form, an email will be sent with all the details (for e.g. first name, last name, comment, etc) a user filled out in the form.
So far if a user fills first name as test, last name as user, email as [email protected], and comment as "This is a test comment", I get an email with the following info:
Name: Test User
Email: [email protected]
Comment: This is a test comment
What I want to do further is to:
a) Send a link in the email which should point to the information a user submitted in the form (I have build a test page, formSubmitted.html which the user sees after the form is submitted)
b) Once the link is opened from the email, I should be able to see, reply, and give feedback to the user's initial comment (lets say saying something like, "Your comment should be, "This is a test comment2" and not "This is a test comment")
c) Finally, a user should get an email with the link where he or she can go and see the comment that I posted ("This is a test comment2") along with his or her initial comment ("This is a test comment")
Is that something that can be done in Flask and flask-mail? or by using some other module in Python?
Thank you for your help.
My code:
__init__py file:
mail = Mail(app)
class MyForm(Form):
firstName = StringField('First name', [validators.Length(min=3, max=35)])
lastName = StringField('Last name', [validators.Length(min=3, max=35)])
Email = StringField('Email Address', [validators.Length(min=4, max=35)])
comment = TextAreaField('Comment', [validators.Length(min=4, max=500)])
@app.route('/', methods=['GET', 'POST'])
def index():
form = MyForm(request.form)
msg = Message("Email from user: " + form.firstName.data + " " + form.lastName.data, sender='[email protected]', recipients=['[email protected]'])
msg.html = "Name: " + form.firstName.data + " " + form.lastName.data + \
" <br />" + "Email: " + form.Email.data + \
"<br /> " + "Comment: " + form.comment.data
mail.send(msg)
return render_template('formSubmitted.html', form=form)
return render_template('index.html', form=form)
if __name__ == "__main__":
app.run(debug=True)
index.html file:
{{ render_field(form.firstName) }}
{{ render_field(form.lastName) }}
{{ render_field(form.Email) }}
{{ render_field(form.comment) }}
formSubmitted.html file:
{% autoescape false %}
{{"Name: " + form.firstName.data + " " + form.lastName.data + "<br />"
+ "Email: " + form.Email.data + "<br /> "
+ "Comment: " + form.comment.data}}
{% endautoescape %}