from flask_mail import Message

from zou.app import mail


def send_email(subject, body, recipient_email, html=None):
    """
    Send an email with given subject and body to given recipient.
    """
    if html is None:
        html = body
    message = Message(
        body=body,
        html=html,
        subject=subject,
        recipients=[recipient_email]
    )
    mail.send(message)

from flask_mail import Message

from zou.app import mail, app


def send_email(subject, body, recipient_email, html=None):
    """
    Send an email with given subject and body to given recipient.
    """
    if html is None:
        html = body
    with app.app_context():
        message = Message(
            body=body,
            html=html,
            subject=subject,
            recipients=[recipient_email]
        )
        mail.send(message)

Fix email sending in production environment
Fix email sending in production environment

  from flask_mail import Message
  
- from zou.app import mail
+ from zou.app import mail, app
  
  
  def send_email(subject, body, recipient_email, html=None):
      """
      Send an email with given subject and body to given recipient.
      """
      if html is None:
          html = body
+     with app.app_context():
-     message = Message(
+         message = Message(
-         body=body,
+             body=body,
-         html=html,
+             html=html,
-         subject=subject,
+             subject=subject,
-         recipients=[recipient_email]
+             recipients=[recipient_email]
-     )
+         )
-     mail.send(message)
+         mail.send(message)
  
Fix email sending in production environment
## Code Before:
from flask_mail import Message

from zou.app import mail


def send_email(subject, body, recipient_email, html=None):
    """
    Send an email with given subject and body to given recipient.
    """
    if html is None:
        html = body
    message = Message(
        body=body,
        html=html,
        subject=subject,
        recipients=[recipient_email]
    )
    mail.send(message)

## Instruction:
Fix email sending in production environment
## Code After:
from flask_mail import Message

from zou.app import mail, app


def send_email(subject, body, recipient_email, html=None):
    """
    Send an email with given subject and body to given recipient.
    """
    if html is None:
        html = body
    with app.app_context():
        message = Message(
            body=body,
            html=html,
            subject=subject,
            recipients=[recipient_email]
        )
        mail.send(message)
