Created
May 26, 2022 08:10
-
-
Save Lukas-Sachse/2c307cb035f3c04734f8572739fbf13f to your computer and use it in GitHub Desktop.
Hook - Send email after form submission (with template)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Location: /templates/anmeldung_angekommen.liquid --> | |
{% layout "base" %} {% block content %} | |
<p>Hallo,</p> | |
<p> | |
Die Anmeldung von <b>{{ vorname }} {{ nachname }}</b> als | |
<b>{{ rolle }}</b> ist bei uns angekommen. | |
</p> | |
<p>Wir werden sie in den nächsten Tagen bearbeiten.</p> | |
<br /> | |
{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Info: Created without using the extension-sdk */ | |
/* Location: /extensions/hooks/YOUR_HOOK_NAME/index.js */ | |
module.exports = function registerHook( | |
{ action }, | |
{ services, exceptions, logger } | |
) { | |
const { MailService } = services; | |
const { ServiceUnavailableException } = exceptions; | |
action("anmeldungen.items.create", async (input, { schema }) => { | |
logger.info("ACTION ANMELDUNG CREATED"); | |
logger.info(" - payload: " + JSON.stringify(input.payload)); // payload contains all used input fields from the form | |
logger.info(" - key: " + JSON.stringify(input.key)); // key contains the id of the created item | |
/* Creating new instances of the MailService */ | |
const mailService = new MailService({ schema }); | |
/* Sending the email. */ | |
try { | |
await mailService.send({ | |
to: input.payload.kontakt_email, | |
subject: "Anmeldung angekommen", | |
template: { | |
name: "anmeldung_angekommen", | |
data: { | |
vorname: input.payload.vorname, | |
nachname: input.payload.nachname, | |
rolle: input.payload.rolle, | |
}, | |
}, | |
attachments: [{ | |
filename: "Anmeldung_angekommen.pdf", | |
path: `https://YOUR_DIRECTUS_URL/assets/YOUR_FILE_ID`, // could be any file url from the internet | |
}], | |
}); | |
} catch (error) { | |
throw new ServiceUnavailableException(error); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment