The ABP Framework provides an abstraction to sending SMS. Having such an abstraction has some benefits;
- You can **easily integrate** to your favorite SMS sender with a few lines of configuration.
- You can then **easily change** your SMS sender without changing your application code.
- If you want to create **reusable application modules**, you don't need to make assumption about how the SMS are sent.
@ -44,7 +43,7 @@ public class YourModule : AbpModule
[Inject](Dependency-Injection.md) the `ISmsSender` into any service and use the `SendAsync` method to send a SMS.
**Example**
**Example:**
```csharp
using System.Threading.Tasks;
@ -66,35 +65,28 @@ namespace MyProject
{
await _smsSender.SendAsync(
"+012345678901", // target phone number
"This is test sms..." // SMS text
"This is test sms..." // message text
);
}
}
}
```
The given `SendAsync` method in the example is an extension method to send sms with primitive paremeters, it basicly creates `SmsMessage` object and pass it. You can also use the default `SendAsync` method which requires `SmsMessage` object.
The given `SendAsync` method in the example is an extension method to send an SMS with primitive parameters. In addition, you can pass an `SmsMessage` object which has the following properties:
> `ISmsSender` is the suggested way to send SMS, since it makes your code provider independent.
## SmsMessage
In addition to use primitive parameters, you can pass a `SmsMessage` object to the `SendAsync` method.
- `PhoneNumber` (string): Target phone number to send sms.
- `Text` (string): SMS Text
- `Properties` (Dictionary<string,string>): string key-value pair to handle different usages by senders.
- `PhoneNumber` (`string`): Target phone number
- `Text` (`string`): Message text
- `Properties` (`Dictionary<string,string>`): Key-value pairs to pass custom arguments
## NullSmsSender
`NullSmsSender` is a built-in class that implements the `ISmsSender`, but writes sms contents to the [standard log system](Logging.md), rathen than actually sending the SMSs.
`NullSmsSender` is a the default implementation of the `ISmsSender`. It writes SMS content to the [standard logler](Logging.md), rather than actually sending the SMS.
This class can be useful especially in development time where you generally don't want to send real sms.
`NullSmsSender` will try to register itself automatically if there is no other registrated sms sender.
This class can be useful especially in development time where you generally don't want to send real SMS. **However, if you want to actually send SMS, you should implement the `IsSmsSender` in your application code.**
## Creating a custom SMS sender
## Implementing the ISmsSender
You can easily create your custom provider by creating a class that implements the `ISmsSender` interface.
You can easily create your SMS sending implementation by creating a class that implements the `ISmsSender` interface, as shown below:
```csharp
using System.IO;
@ -114,8 +106,6 @@ namespace AbpDemo
}
```
That's all. Now you can send SMS by using `MyCustomSmsSender` in your application.
## See also
## More
- [Twilio SMS Sender](https://docs.abp.io/en/commercial/latest/modules/twilio-sms) with [ABP Commercial](https://commercial.abp.io/).
[ABP Commercial](https://commercial.abp.io/) provides Twilio integration package to send SMS over [Twilio service](https://docs.abp.io/en/commercial/latest/modules/twilio-sms).