Initial commit
This commit is contained in:
42
PartSource.Automation/Services/EmailService.cs
Normal file
42
PartSource.Automation/Services/EmailService.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using PartSource.Automation.Models.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Net.Mail;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PartSource.Automation.Services
|
||||
{
|
||||
public class EmailService
|
||||
{
|
||||
private readonly EmailConfiguration _emailConfiguration;
|
||||
|
||||
public EmailService(EmailConfiguration emailConfiguration)
|
||||
{
|
||||
_emailConfiguration = emailConfiguration;
|
||||
}
|
||||
|
||||
public void Send(string subject, string body)
|
||||
{
|
||||
using (SmtpClient smtpClient = new SmtpClient { Host = _emailConfiguration.SmtpHost })
|
||||
{
|
||||
MailMessage mailMessage = new MailMessage
|
||||
{
|
||||
From = new MailAddress(_emailConfiguration.From),
|
||||
Subject = subject,
|
||||
Body = body,
|
||||
IsBodyHtml = true
|
||||
};
|
||||
|
||||
foreach (string address in _emailConfiguration.To.Split(','))
|
||||
{
|
||||
mailMessage.To.Add(address);
|
||||
}
|
||||
|
||||
smtpClient.Send(mailMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user