-
-
Notifications
You must be signed in to change notification settings - Fork 10
Home
The flask-mailing simple lightweight mail system, sending emails and attachments(individual && bulk) fully asynchronously.
Flask_Mail is dead now. To use the mail service with your project you can use eaither Flask-Mailing for legacy or Flask-Mailman for Django type implementation.
from flask import Flask, jsonify
from flask_mailing import Mail, Message
mail = Mail()
def create_app():
app = Flask(__name__)
app.config['MAIL_USERNAME'] = "your-email@your-domain.com"
app.config['MAIL_PASSWORD'] = "world_top_secret_password"
app.config['MAIL_PORT'] = 587
app.config['MAIL_SERVER'] = "your-email-server.com"
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USE_SSL'] = False
app.config['MAIL_DEFAULT_SENDER'] = "your-email@your-domain.com"
mail.init_app(app)
return app
#send a simple email using flask_mailing module.
app = create_app()
@app.get("/email")
async def simple_send():
message = Message(
subject="Flask-Mailing module",
recipients=["aniketsarkar@yahoo.com"],
body="This is the basic email body",
)
await mail.send_message(message)
return jsonify(status_code=200, content={"message": "email has been sent"})
In order to use Jinja template langauge, your must specify email folder within your applications working directory.
In sending HTML emails, the CSS expected by mail servers -outlook, google, etc- must be inline CSS. Flask mail passes "body" to the rendered template. In creating the template for emails the dynamic objects should be used with the assumption that the variable is named "body" and that it is a python dict.
check out jinja2 for more details jinja2
The utility allows you to check temporary email addresses, you can block any email or domain. You can connect to Redis to save and check email addresses. If you do not provide a Redis configuration, then the utility will save it in the list or set it by default.
Flask mailing allows you to write unittest for your application without sending emails to non existent email address by mocking the email to be sent. To mock sending out mails, set the suppress configuration to true. Suppress send defaults to False to prevent mocking within applications.
Use this just like bcc but to specify addresses that should receive a reply to your message. E-mail systems MAY respect this as per RFC 2822.