Add SendEmail ไปที่ระบบออกคำสั่ง
This commit is contained in:
parent
648d940b57
commit
68a8ca9d9f
6 changed files with 69 additions and 16 deletions
|
|
@ -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