from flask import Flask from flask_mail import Mail, Message app = Flask(__name__) mail = Mail(app) msg = Message('Hello', recipients=['[email protected]']) msg.body = 'testing' mail.send(msg)
from flask import Flask, render_template from flask_mail import Mail, Message app = Flask(__name__) mail = Mail(app) msg = Message('Hello', recipients=['[email protected]']) msg.html = render_template('email.html', name='John Doe') mail.send(msg)
from flask import Flask from flask_mail import Mail, Message app = Flask(__name__) mail = Mail(app) with app.open_resource("image.png") as file: msg = Message('Hello', recipients=['[email protected]']) msg.body = 'testing' msg.attach('image.png', 'image/png', file.read()) mail.send(msg)In each example, we initialize the Flask-Mail object with our Flask application instance, then create a Message object with our desired subject, recipient(s), and content. Finally, we use the Mail object's send method to send the message. Overall, Python Flask-Mail is a powerful and convenient package library to use for sending emails within Flask applications.