Skip to content

Instantly share code, notes, and snippets.

@hishaamn
Created April 11, 2024 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hishaamn/23a14fd34d1a2daaccc8620bf9b081ce to your computer and use it in GitHub Desktop.
Save hishaamn/23a14fd34d1a2daaccc8620bf9b081ce to your computer and use it in GitHub Desktop.
[HttpPost]
public IHttpActionResult SendExternalFormEmail(EmailData data)
{
IMessageBus<AutomatedMessagesBus> automatedMessageBus = ServiceLocator.ServiceProvider.GetService<IMessageBus<AutomatedMessagesBus>>();
var contact = new ContactIdentifier(data.Source, data.ContactIdentifier, ContactIdentifierType.Known);
var dictionary = new Dictionary<string, object>();
foreach (var formData in data.FormData)
{
dictionary.Add(formData.Key, formData.Value);
}
var automatedMessage = new AutomatedMessage()
{
ContactIdentifier = contact,
MessageId = new Guid(data.EmailCampaignId),
CustomTokens = dictionary,
TargetLanguage = Sitecore.Context.Language.Name
};
automatedMessageBus.Send(automatedMessage);
var status = new Status
{
StatusCode = "Status 200"
};
var apiResponse = new ApiResponse<Status>
{
Result = status,
StatusCode = "Api Status 200"
};
return Json(new { status = HttpStatusCode.OK, response = apiResponse });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment