I am looking to allow users to login with their gmail accounts and send emails from these personal accounts. So far, I have the following code which works properly. Upon startup, an email is sent from the sender to the recipient:
from flask import Flask from flask_mail import Mail, Message app = Flask(__name__) # sender email information configuration app.config.update(dict( DEBUG = True, MAIL_SERVER = 'smtp.gmail.com', MAIL_PORT = 587, MAIL_USE_TLS = True, MAIL_USE_SSL = False, MAIL_USERNAME = 'email@example.com', MAIL_PASSWORD = 'my_password', )) mymail = Mail(app) @app.route('/') def index(): # outgoing message msg = Message("Hello", sender=("Me", "firstname.lastname@example.org"), recipients=["email@example.com"], body="This is a test email I sent with Gmail and Python!") mymail.send(msg) if __name__ == '__main__': app.run() # message sent confirmation return "Your mail has been sent!"
Now, I want to allow the user to login using their gmail accounts and, upon pressing a button, send out an email. However, I'm not sure how to handle the user's gmail password properly. I read up on bcrypt, but I'm not sure how to implement for this particular application. Thank you.