Performance: Why email matters in web apps
Email handling affects backend response times and user experience during interactions like sign-up and password reset.
from threading import Thread def send_async_email(app, msg): with app.app_context(): mail.send(msg) def register_user(): user = create_user() Thread(target=send_async_email, args=(app, create_email(user.email, 'Welcome!'))).start() return 'Registration complete'
def register_user(): user = create_user() send_email(user.email, 'Welcome!') # synchronous call return 'Registration complete'
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous email sending | 0 | 0 | Blocks initial paint until server responds | [X] Bad |
| Asynchronous email sending | 0 | 0 | Allows immediate paint after server response | [OK] Good |
from flask_mail import Mail, Message mail = Mail() msg = Message(subject='Hello', sender='app@example.com', recipients=['user@example.com']) msg.body = 'Welcome!' mail.send(msg)
msg = Message('Reset', sender='noreply@site.com', recipients='user@site.com')
msg.body = 'Click link to reset.'
mail.send(msg)Pass the test and this pattern moves unknown