M# Tutorials

Learn to build .NET applications with M#. Our step-by-step tutorials will get you up-to-speed rapidly.
If you already know ASP.NET and C#, you can master M# in a week or two.

Sending SMS

In this tutorial we go through the implementation of sending an SMS using M# framework. We will take a look at the interfaces, classes and configuration required to set up SMS sending functionality.


M# Framework exposes this interface under "Msharp.Framework.Services" namespace, which must be implemented in order to send SMS. This interface defines the contents of the actual SMS and is implemented on an entity class, which is used to store SMS related information in database. The screenshot below shows ISmsQueueItem definition

ISmsQueueItem Implementation

You must create an entity in M# which implements ISmsQueueItem in business logic. This tutorial does not explain the steps to implement the ISmsQueueItem interface as it follows same steps we performed in tutorial Sending Email for implementing IEmailQueueItem.

ISMSSender Interface

M# doesn’t provide default logic for sending an SMS but exposes ISMSSender interface, which defines only one method. This interface must be implemented and the method should implement the logic of sending an SMS. You should not write any exception handling logic in this method. Any exception in this method will be handled by M# engine and will be logged. The screenshot below shows ISMSSender definition:

SMS Configuration

M# framework looks for the two app settings in the configuration file shown below

"SMS.Maximum.Retries" is an optional setting, which is used to determine the maximum number of reties M# engine should perform to send an SMS. M# engine reties 3 times by default when this setting is not provided.

"SMS.Sender.Type" is a required setting, which is used to load the instance of type that implements ISMSSender interface. M# throws exception if type is not defined or doesn’t implement ISMSSender interface.


M# framework exposes a static class SmsService under "Msharp.Framework.Services" which is responsible for sending SMS. You must define an "Automatic Task" in M#, which calls the appropriate method to send an SMS (please read tutorial Automatic Task for more details)

SmsService class exposes one public event handler which can be used to capture exceptions and two methods to send the SMS. The screenshot below shows the definition of SmsService class.

Note: You must implement ISMSSender in your project, which should contain the SMS sending logic. "Send" method implemented in SmsService doesn’t contain the logic to send SMS. It handles the ISmsQueueItem instance and invokes ISMSSender implantation to send an SMS and maintains the retries. "SendAll" method tries to send all the "SMSQueueItems" pending in the database table not marked as sent.