using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Essentials;

namespace Navigator.Integration
{
  public class SMSClient
  {
    private SMSClient()
    {
    }
    public static void SendSMSEmail(string message, String from, String[] recipients,String smtpAddress,String userName,String password,int port=587)
    {
      String subject = string.Format("{0} {1}", message, DateTime.Now);

      try
      {
        if (!(Connectivity.NetworkAccess==Connectivity.NetworkAccess)) return;
        //{
        //  MDTrace.WriteLine(LogLevel.DEBUG,"The internet is not connected.  Cannot send SMSEmail.");
        //  return;
        //}
        MailMessage mailMessage = new MailMessage();
        mailMessage.From = new MailAddress(from);
        mailMessage.Body = message;
        mailMessage.IsBodyHtml = false;
        foreach (String recipient in recipients)
        {
          mailMessage.To.Add(new MailAddress(recipient));
        }
        SmtpClient smtpClient = new SmtpClient(smtpAddress,port);                    //  smtp.gmail.com
        smtpClient.UseDefaultCredentials = false;
        smtpClient.Credentials = new System.Net.NetworkCredential(userName,password);   // skessler1964@gmail.com MN5191306B
        smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
        smtpClient.EnableSsl = true;
        smtpClient.Send(mailMessage);
      }
      catch (System.Exception)
      {
//        MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString());
      }
    }
  }
}
