Send SMS/MMS in web forms using a custom processor
The Send MMS and Send SMS save actions delegate sending messages to gateways through a SMTP server.
In the Web Forms for Marketers module, you can send SMS and MMS messages using the Send SMS and Send MMS save actions respectively. The Send MMS and the Send SMS save actions delegate sending messages to an MMS/SMS gateway through an SMTP server.
You can use the processMessage
pipeline to change this behavior and send messages, for example, through a third-party paid web service.
To send messages through a third party web service using the processMessage
pipeline:
In Visual Studio, in the
Sitecore.Form.Core.Pipelines.ProcessMessage
namespace, create a new processor using the following sample code:namespace Sitecore.Form.Core.Pipelines.ProcessMessage { using System.IO; using System.Net; public class SendSMSorMMS { public void Process(ProcessMessageArgs args) { if (args.MessageType == MessageType.MMS || args.MessageType == MessageType.SMS) { WebClient wc = new WebClient(); wc.Credentials = (NetworkCredential)args.Credentials; wc.QueryString.Add("sendto", args.Recipient); wc.QueryString.Add("message", args.Mail.ToString()); if (!string.IsNullOrEmpty(args.From)) { wc.QueryString.Add("from", args.From); } using (Stream responseStream = wc.OpenRead("https://3rdparty.smsormms.com/")) { using (StreamReader responseReader = new StreamReader(responseStream)) { responseReader.ReadToEnd(); responseReader.Close(); responseStream.Close(); } } } } } }
In the
Sitecore.Forms.config
file, register the new processor:<processMessage> <processor type="Sitecore.Form.Core.Pipelines.ProcessMessage.ProcessMessage, Sitecore.Forms.Core" method="ExpandLinks"/> <processor type="Sitecore.Form.Core.Pipelines.ProcessMessage.ProcessMessage, Sitecore.Forms.Core" method="ExpandTokens"/> <processor type="Sitecore.Form.Core.Pipelines.ProcessMessage.ProcessMessage, Sitecore.Forms.Core" method="AddHostToItemLink"/> <processor type="Sitecore.Form.Core.Pipelines.ProcessMessage.ProcessMessage, Sitecore.Forms.Core" method="AddHostToMediaItem"/> <processor type="Sitecore.Form.Core.Pipelines.ProcessMessage.ProcessMessage, Sitecore.Forms.Core" method="AddAttachments"/> <processor type="Sitecore.Form.Core.Pipelines.ProcessMessage.ProcessMessage, Sitecore.Forms.Core" method="BuildToFromRecipient"/> <processor type="Sitecore.Form.Core.Pipelines.ProcessMessage.SendSMSorMMS, MyAssembly"/> <processor type="Sitecore.Form.Core.Pipelines.ProcessMessage.ProcessMessage, Sitecore.Forms.Core" method="SendEmail"/> </processMessage>
From the Sitecore Desktop, open the Form Designer and in the relevant form, add the Send SMS or Send MMS save action. As an optional step, submit the form to ensure that the custom processor works correctly.