add message queue table for notification system
This commit is contained in:
parent
1c99718a30
commit
841bf32175
12 changed files with 21322 additions and 3 deletions
60
BMA.EHR.Infrastructure/Messaging/EmailSenderService.cs
Normal file
60
BMA.EHR.Infrastructure/Messaging/EmailSenderService.cs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
using BMA.EHR.Domain.Extensions;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Net;
|
||||
using System.Net.Mail;
|
||||
|
||||
namespace BMA.EHR.Infrastructure.Messaging
|
||||
{
|
||||
public class EmailSenderService
|
||||
{
|
||||
#region " Fields "
|
||||
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Constructor and Destructor "
|
||||
|
||||
public EmailSenderService(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Methods "
|
||||
|
||||
public void SendMail(string subject, string body, string receiver)
|
||||
{
|
||||
try
|
||||
{
|
||||
var server = _configuration["Mail:Server"];
|
||||
var user = _configuration["Mail:User"];
|
||||
var password = _configuration["Mail:Password"];
|
||||
var port = _configuration["Mail:Port"];
|
||||
var from = _configuration["Mail:MailFrom"];
|
||||
|
||||
var client = new SmtpClient(server, port.ToInteger());
|
||||
client.UseDefaultCredentials = false;
|
||||
client.Credentials = new NetworkCredential(user, password);
|
||||
client.EnableSsl = true;
|
||||
client.DeliveryMethod = SmtpDeliveryMethod.Network;
|
||||
|
||||
|
||||
var mail = new MailMessage();
|
||||
mail.From = new MailAddress(from, "eHR Bangkok Automation System");
|
||||
mail.To.Add(receiver);
|
||||
mail.Subject = subject;
|
||||
mail.Body = body;
|
||||
mail.IsBodyHtml = true;
|
||||
client.Send(mail);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue