I'd like to create an automated email campaign in EXM. I'd like this campaign to be triggered when a form is submitted. This form is not a Sitecore Form, it is not placed in a Sitecore website. Is this possible?
- Have you looked at this? doc.sitecore.com/xp/en/developers/exm/90/…Richard Seal– Richard Seal ♦2023-11-06 14:17:18 +00:00Commented Nov 6, 2023 at 14:17
- I think it possible. You need to push the data from your form to the automated message queue found in the messaging database. From there, the automated handler will trigger the email sending process.Hishaam Namooya– Hishaam Namooya2023-11-06 17:39:44 +00:00Commented Nov 6, 2023 at 17:39
- You should have a mechanism in place that triggers the handler in Sitecore which sends the automated email. It can be an api request or an entry in a database table/queue.Ghan– Ghan2023-11-07 17:09:23 +00:00Commented Nov 7, 2023 at 17:09
1 Answer
As mentioned in the comments already you can do this if you create an endpoint on your Sitecore site that can trigger the mail. To do this you can use the EXM api as described in the docs: https://doc.sitecore.com/xp/en/developers/exm/103/email-experience-manager/sending-email-campaigns-programmatically.html. The example from there for automated emails:
IMessageBus<AutomatedMessagesBus> automatedMessageBus = ServiceLocator.ServiceProvider.GetService<IMessageBus<AutomatedMessagesBus>>(); AutomatedMessage automatedMessage = new AutomatedMessage() { ContactIdentifier = contactIdentifier, MessageId = emailCampaignId }; automatedMessageBus.Send(automatedMessage); Trigger this endpoint when the form has been submitted and your campaign should be send.
If you need something more complex, you can also have a look at the code from the "Forms Extensions" module that has a SendMail submit action capable of replacing tokens in regular EXM mails with form data. Although this is a submit action and as such attached to Sitecore Forms, it might help or inspire you to achieve what is needed. That code can be found on Github.