1from flask import Flask
2from flask_mail import Mail, Message
3import os
4
5app = Flask(__name__)
6
7mail_settings = {
8 "MAIL_SERVER": 'smtp.gmail.com',
9 "MAIL_PORT": 465,
10 "MAIL_USE_TLS": False,
11 "MAIL_USE_SSL": True,
12 "MAIL_USERNAME": os.environ['EMAIL_USER'],
13 "MAIL_PASSWORD": os.environ['EMAIL_PASSWORD']
14}
15
16app.config.update(mail_settings)
17mail = Mail(app)
18
1if __name__ == '__main__':
2 with app.app_context():
3 msg = Message(subject="Hello",
4 sender=app.config.get("MAIL_USERNAME"),
5 recipients=["<recipient email here>"], # replace with your email for testing
6 body="This is a test email I sent with Gmail and Python!")
7 mail.send(msg)
8