Following this approach all you need to do is simply send an email using the standard .NET libraries (System.Net.Mail) with a specific string format with a combination of the recipient's mobile number and service provider account (this will most defenitly be specific to your service provider). Sharepoint
Below I will give you some sample C# code to achieve this:
[CrmWorkflowActivity("Send SMS", "My Custom WF Activities")]
public partial class SendSMS: SequenceActivity
{
//DEV NOTE: Ensure that the name of the property (public string mobileNumber{}) match that of the name passed to DependencyProperty.Register
public static DependencyProperty mobileNumberProperty = DependencyProperty.Register("mobileNumber", typeof(string), typeof(SendSMS));
public static DependencyProperty messageProperty = DependencyProperty.Register("message", typeof(string), typeof(SendSMS));
[CrmInput("mobilenumber")]
[CrmDefault("")]
public string mobileNumber
{
get { return (string)base.GetValue(mobileNumberProperty); }
set { base.SetValue(mobileNumberProperty, value); }
}
[CrmInput("message")]
[CrmDefault("Type your sms message here")]
public string message
{
get { return (string)base.GetValue(messageProperty); }
set { base.SetValue(messageProperty, value); }
}
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
IWorkflowContext wfContext = contextService.Context;
ICrmService crmService = wfContext.CreateCrmService(true);
SendNewSMS(mobileNumber, message);
return ActivityExecutionStatus.Closed;
}
private void SendNewSMS(string mobileNr, string message)
{
string host = "localhost";
SmtpClient client = new SmtpClient(host);
MailAddress toAddress = new MailAddress(string.Format("{0}@myprovider.com", mobileNr));
MailAddress fromAddress = new MailAddress("account@myorg.com");
MailMessage msg = new MailMessage(fromAddress, toAddress);
msg.Subject = message;
msg.Body = string.Empty;
client.Send(msg);
}
No comments:
Post a Comment