68 lines
1.4 KiB
C#
68 lines
1.4 KiB
C#
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
|
|
};
|
|
|
|
using 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);
|
|
}
|
|
|
|
public void Send(string to, string subject, string body)
|
|
{
|
|
using SmtpClient smtpClient = new SmtpClient
|
|
{
|
|
Host = _emailConfiguration.SmtpHost
|
|
};
|
|
|
|
using MailMessage mailMessage = new MailMessage
|
|
{
|
|
From = new MailAddress(_emailConfiguration.From),
|
|
Subject = subject,
|
|
Body = body,
|
|
IsBodyHtml = false
|
|
};
|
|
|
|
foreach (string address in _emailConfiguration.To.Split(','))
|
|
{
|
|
mailMessage.To.Add(to);
|
|
}
|
|
|
|
smtpClient.Send(mailMessage);
|
|
}
|
|
}
|
|
}
|