Email outlook using Flask

Asked

Viewed 126 times

-1

I’m trying to create a code that sends email outlook with flask, but for some reason it won’t, I tested with gmail, tbm is not going

from flask import Flask
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'] = '[email protected]
app.config['Mail_PASSWORD'] = '******'
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USE_SSL'] = False
app.config['MAIL_ASCII_ATTACHMENT'] = False

mail = Mail(app)

@app.route('/')
def index():
    msg = Message('hello', sender='[email protected]', recipients=['[email protected]'])
    return 'Message Sent'


if __name__ == "__main__":
    app.run(debug=True)

1 answer

0

In the sent code only the sending message is being created, and the sending process is missing. It is missing the line that will send the e-mail.

mail.send(msg)

The function should be as follows:

@app.route('/')
def index():
    msg = Message('hello', sender='[email protected]', recipients=['[email protected]'])
    mail.send(msg)
    return 'Message Sent'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.