Merge branch 'develop' into work
This commit is contained in:
commit
e7c71b2e15
6 changed files with 1063 additions and 20 deletions
|
|
@ -1,6 +1,5 @@
|
|||
using BMA.EHR.Application.Common.Interfaces;
|
||||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Infrastructure.Messaging;
|
||||
using BMA.EHR.Infrastructure.Persistence;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
|
@ -14,7 +13,7 @@ namespace BMA.EHR.Infrastructure
|
|||
IConfiguration configuration)
|
||||
{
|
||||
services.AddTransient<MinIOService>();
|
||||
services.AddTransient<EmailSenderService>();
|
||||
|
||||
|
||||
var connectionString = configuration.GetConnectionString("DefaultConnection");
|
||||
|
||||
|
|
|
|||
|
|
@ -1,60 +0,0 @@
|
|||
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