using System.Net.Mail;

namespace FamilyTreeAPI.Repository
{
    public class Email
    {
        public static void SendMail(string smtpServer, string sender, string sendTo,
            string header, string message, bool mailPriority = false)
        {
            if (string.IsNullOrEmpty(smtpServer) && string.IsNullOrEmpty(sender) && string.IsNullOrEmpty(sendTo))
                return;

            System.Net.Mail.SmtpClient client = new SmtpClient(smtpServer);
            MailMessage mailMessage = new MailMessage();
            mailMessage.From = new MailAddress(sender);

            var splitEmails = sendTo.Split(';');
            foreach (string item in splitEmails)
            {
                mailMessage.To.Add(item);
            }
            if (mailPriority)
                mailMessage.Priority = MailPriority.High;

            //  mailMessage.To.Add(sendTo);
            mailMessage.Subject = header;
            string text = message;
            string signature = "";
            try
            {
                text += "<br/>" + signature;
                mailMessage.Body = text;
                mailMessage.IsBodyHtml = true;

            }
            catch //(Exception ex)
            {
                //  ErrorLogger.logError(ex, "CPA");
                throw;
            }

            try
            {
                string userState = "send to fleet manager";
                client.SendAsync(mailMessage, userState);

            }
            catch //(Exception ex)
            {
                throw;
            }
        }
    }
}
