Your plugin can add a new way to send emails, like Amazon SES or another email service. The admin selects it in Settings > Email as the email protocol. It can also be selected for ticket emails in Settings > Tickets > Email settings.
Add the protocol to the list
app_hooks()->add_filter("app_filter_email_protocols", function ($protocols, $options) {
$protocols["my_plugin_ses"] = "Amazon SES";
return $protocols;
}, 10, 2);
$options["context"] is "default" on the Email settings page and "tickets" on the ticket email settings tab. Don't add your protocol to a context you don't support.
Show your fields
Print your fields on the settings page. Put them inside a div with data-email-protocols. RISE shows the div only when your protocol is selected.
app_hooks()->add_action("app_hook_email_settings_extension", function ($options) {
$name = $options["setting_prefix"] . "my_plugin_ses_region";
echo '';
echo '';
echo '';
echo '<input type="text" id="' . $name . '" name="' . $name . '" value="' . esc(get_setting($name)) . '" class="form-control">';
echo '';
echo '';
});
- $options["setting_prefix"] is "" on the Email settings page and "ticket_" on the ticket tab. Add it to your field names, so the two pages keep their own values.
- The "Email sent from name" and "Email sent from address" fields are shown for your protocol too.
- Show "******" for saved secrets, and keep the saved value when this comes back.
- If your protocol needs an authorization (like OAuth), add data-setting-prefix and data-authorize-url to your div. RISE opens that page after saving.
echo '';Save your fields
app_hooks()->add_action("app_hook_email_settings_save_data", function ($options) { $name = $options["setting_prefix"] . "my_plugin_ses_region"; $Settings_model = model("App\Models\Settings_model"); $Settings_model->save_setting($name, clean_data((string) service("request")->getPost($name))); });This runs before the test email is sent, so the admin can test your settings with the "Send test mail to" field.
Send the emails
RISE calls this filter for every email when your protocol is selected. Send the email and return true or false. Return $result as it is for other protocols.
app_hooks()->add_filter("app_filter_send_app_mail", function ($result, $data) { if ($data["protocol"] !== "my_plugin_ses") { return $result; } $settings = $data["email_settings"]; $region = get_setting($settings["setting_prefix"] . "my_plugin_ses_region"); //send $data["message"] to $data["to"] from $settings["from_address"] here return true; }, 10, 2);
Key of $data What it is protocol The selected protocol. to One email address or an array of addresses. subject The subject. message The HTML message. options attachments (array of file_path and file_name), reply_to, cc, bcc, headers (array with In-Reply-To and References for ticket emails to clients; use get_email_thread_headers($options) to get the cleaned values and add them to your email, so it shows in the client's mail thread). email_settings context ("default" or "tickets"), setting_prefix, from_name, from_address.
- If no plugin sends the email, RISE writes an error in the log and the email is not sent.
- Ticket emails use the ticket settings only when a protocol is selected on the ticket tab. Otherwise they use the main email settings.