Skip to content

Creating an Email

William O'Beirne edited this page Jan 6, 2019 · 1 revision

If you need to add a new email for some event, here's how you do it:

Make a New Template

Create a .html and a .txt file of the same name in backend/grant/templates/emails/. Both email's contents should match each other.

Setup the Parameters

Add the email's parameters to backend/grant/email/send.py. Copy one of the existing emails to see what's needed. Make sure the name of the parameter function / lookup key matches the file names you made in the previous step.

Preview & Test

Add some example parameters in backend/grant/admin/example_emails.py, and add an entry for the email in admin/src/components/Emails/emails.ts. Test the email by going to http://localhost:3500/emails and clicking on your email.

Add Send Code

Where you actually want the email to trigger a send, add the following:

from grant.email.send import send_email

# ...

send_email(to_email, 'email_id', {
  'args': 'for',
  'email': 'templates',
  # ...
})

send_email will handle everything about sending logic, and doesn't need to be try / catch'd. Make sure you actually run this and have the email sent to your inbox to confirm the way it looks.