signebedi / libreforms-fastapi

FastAPI implementation of the libreForms spec
GNU Affero General Public License v3.0
1 stars 1 forks source link

Implement `send_mail` built in event hook behavior #313

Closed signebedi closed 3 months ago

signebedi commented 3 months ago

This will look something like:

send_mail:
  template: form_created
  method: static
  target: bob@hr.example.com

Where the template points to one of the template names in the email config, method is an enum of ['static', 'group', and 'relationship'], and target is the value used to select the emails to send, based on the method. So, the example above will always send Bob a form_created email to bob@hr.example.com when a form is submitted. But, if we wanted to send this to all members of the default group, we could do the following:

send_mail:
  template: form_created
  method: group
  target: default

Originally posted by @signebedi in https://github.com/signebedi/libreforms-fastapi/issues/210#issuecomment-2211812137

signebedi commented 3 months ago

I think the format will need to change slightly, along the lines of:

on_create:
  - type: send_mail
    template: form_created
    method: static
    target: bob@hr.example.com

This will ensure we create a list of dicts.

ALSO: static target should split and trim on commas, so we can send to multiple people with one entry.

signebedi commented 3 months ago

[bug] send mail event hook fails with multiple recipients In Python 2, you should be able to just use comma separated list represented as a string. https://stackoverflow.com/a/12422921. However, apparently this does not work in Python 3 and we need to use send_message instead, see https://docs.python.org/3/library/email.examples.html.