Implementation of gov service MNotify
- Install package from nuget
Install-Package GR.Notifications.MNotify
- Register th services:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
private IConfiguration Configuration { get; }
//...
public void ConfigureServices(IServiceCollection services)
{
//...
services.AddMNotify(Configuration);
//...
}
//...
}
- Add configuration on your appsettings.json file:
{
"MNotifyOptions": {
"ServiceClientAddress": "https://testmnotify.gov.md:8443/MNotify.svc",
"ServiceCertificatePath": "<certificate file name>.pfx",
"ServiceCertificatePassword": "<certificate password>"
}
}
ServiceClientAddress
- url of service
ServiceCertificatePath
- physical path to pfx certificate
ServiceCertificatePassword
- certificate password
- Inject MNotify Service and send notifications
public class FooService{
private readonly IMNotifyService _service;
public FooService(IMNotifyService _service){
_service = service;
}
public async Task FooMethodAsync(){
var sendResult = await mNotifyService.SentNotificationAsync(new MNotifyNotification
{
Sender = new MNotifyPerson("UserName", "foo@foo.com"),
Recipient = new MNotifyPerson("UserName", "foo@foo.com"),
NotificationType = "Test",
Subject = "Notification subject",
Content = "Test notification"
});
}
}