email_utils.py

About this file

This file contains functions for sending emails to a contact and for sending emails with attachments. The file also contains a function to return a list of emails of admins, users, and the agency default email.

Functions explanation:
'send_email(subject, to=list(), cc=list(), bcc=list(), template=None, email_content=None, **kwargs)'
This function sends asynchronous emails for the application by taking arguments from the frontend.

'get_agency_emails(request_id, admins_only=False)'
It gets a list of the agency emails (assigned users and default email). It returns a list of agency emails or ['agency@email.com'] (for testing) using parameters FOIL request ID and the return list of agency admin emails.

Code Issues

  • Missing docstring for send_async_email(msg)
  • Missing docstring for send_contact_email(subject, recipients, body, sender)
  • Line 53 uses assert.
    It was discovered that some projects used assert to enforce interface constraints. However, assert is removed with compiling to optimized byte code (python -o producing *.pyo files). This caused various protections to be removed. The use of assert is also considered as general bad practice in OpenStack codebases.

    Instead, a simple if condition can be used.

      
      if not condition:
          raise AssertionError()
      
      

Code Check Report


No problems to report
                        

Documentation drawn from source code


app.lib.email_utils
~~~~~~~~~~~~~~~~

Implements e-mail notifications for OpenRecords. Flask-mail is a dependency, and the following environment variables
need to be set in order for this to work: (Currently using Fake SMTP for testing)
MAIL_SERVER: 'localhost
MAIL_PORT: 2500
MAIL_USE_TLS: FALSE
MAIL_USERNAME: os.environ.get('MAIL_USERNAME')
MAIL_PASSWORD: os.environ.get('MAIL_PASSWORD')
DEFAULT_MAIL_SENDER: 'Records Admin


send_async_email(msg):

send_contact_email(subject, recipients, body, sender):

send_email(subject, to=list(), cc=list(), bcc=list(), reply_to='', template=None, email_content=None, **kwargs):
Function that sends asynchronous emails for the application.
Takes in arguments from the frontend.

Args:
to: Person(s) email is being sent to
cc: Person(s) being CC'ed on the email
bcc: Person(s) being BCC'ed on the email
reply_to: reply-to address
subject: Subject of the email
template: HTML and TXT template of the email content
email_content: string of HTML email content that can be used as a message template
kwargs: Additional arguments the function may take in (ie: Message content)

get_assigned_users_emails(request_id: str):
Gets a list of all the assigned users' emails on a request and the agency's default email.

Args:
request_id: Request ID

Returns:
A unique list of all the assigned users' emails on a request and the agency's default email.

get_agency_admin_emails(agency: Agencies):
Gets a list of all the agency administrators' emails in an agency.

Args:
agency: An Agencies instance

Returns:
A unique list of all the agency administrators' emails in an agency.

Source code