Advanced Mail Functions
With bigger and bigger applications being built with Structr, it became evident that there was a need for more flexible ways of sending emails from within Structr than the two existing mail functions provided. Even simple concepts like multiple recipients, CC or BCC were impossible. So I sketched out a couple of ideas and discussed with the team how to make sending emails great again (SCNR).
The core design goal for the Advanced Mail Module was maximum flexibility. This is why all of the new mail functions can be used incrementally until the email is fully configured and ready to be sent. If need be, a fully configured email can also be changed and sent in a different configuration. Every parameter that can be set, can be cleared or at least overwritten (for mandatory parameters).
- Required parameters
- Sender address
- HTML content
- at least one recipient address (either as TO:, CC: or BCC:)
- Optional parameters
- Sender name
- Text content
- Additional recipient address(es) with optional name(s) (either as TO:, CC: or BCC:)
- Attachment(s) (with optional filename instead of the ‘real’ filename)
- Reply-To address(es)
- Bounce address
- Custom mail header(s)
The basic setup always consists of calling the `mail_begin()` function, adding additional configuration parameters via any of the `mail_add_...()` functions and finally sending the fully configured mail using the `mail_send()` function. Afterwards the mail is still available and fully configured and can be altered and sent again. This allows for use cases like mass emails where for example the subject line or the body is personalised for every recipient.
With the 20 new functions to configure the mail instead of only 2, we believe we reached the goal of making the mail sending process a lot more flexible and a lot less painful.