2024-06-15 01:51:32 +04:00
|
|
|
|
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
|
|
|
|
|
{
|
2024-06-22 21:15:11 +04:00
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
if (!mail.IsSendable) return;
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-15 01:51:32 +04:00
|
|
|
|
}
|