I'm trying to follow an online tutorial to use flask email in sending emails. But I get a 405 Not Allowed message when I submit the form. Unfortunately the author doesn't exlain anything about these error messages. I'm using google as the mail server. Can someone see where I'm going wrong? Thanks in advance. here's the code:
import os
from flask import Flask, render_template, request
from flask_mail import Mail, Message
app = Flask(__name__)
app.config['MAIL_SERVER'] = 'smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USERNAME'] = 'milestone2020.projects@gmail.com'
app.config['MAIL_PASSWORD'] = '******'
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True
mail = Mail(app)
@app.route('/')
def index():
return render_template('home.html')
@app.route('/send_message', methods=['GET', 'POST'])
def send_message():
if request.method == 'POST':
email = request.form['email']
subject = request.form['subject']
msg = request.form['message']
message = Message(subject, sender='milestone2020.projects@gmail.com',
recipients=[email])
message.body = msg
mail.send(message)
success = "Message sent"
return render_template('result.html', success=success)
if __name__ == '__main__':
app.run(debug = True)er code here
This is the form at **home.html**.
<form action="{{url_for('send_message')}}" method="POST">
<input type="email" id="email" name="email" placeholder="Email" required><br><br>
<input type="text" id="subject" name="subject" placeholder="subject" required><br><br>
<textarea name="message" id="message" cols="30" rows="10" placeholder="Message body"></textarea>
<br><br>
<input type="submit" value="Submit">
</form>
**result.html**