using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Mail; using System.Text; using System.Threading.Tasks; namespace BusinessLogic.Tools.Mail { public class MailSender { private static string _email; private static string _password; private static string _smtpClientHost; private static short _smtpClientPort; public void SetupMailOptions(MailOptions options) { _email = options.Email; _password = options.Password; _smtpClientHost = options.SmtpClientHost; _smtpClientPort = options.SmtpClientPort; } public static void Send(Mail mail) { using SmtpClient client = new SmtpClient(_smtpClientHost, _smtpClientPort); client.Credentials = new NetworkCredential(_email, _password); client.EnableSsl = true; using MailMessage message = new MailMessage(); message.From = new MailAddress(_email); foreach (string to in mail.To) { message.To.Add(to); } message.Subject = mail.Title; message.Body = mail.Body; client.Send(message); } } }