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

namespace MarketData.Integration
{
  public class SMSClient
  {
    private SMSClient()
    {
    }

//    <add key="sms_smtpaddress" value="smtp.gmail.com"/>
//    <add key="sms_smsusername" value="skessler1964@gmail.com"/>
//		<add key="sms_smspassword" value="hebo cfmi qpjf oyii"/>
//    <add key="sms_smsrecipients" value="6315252496@vtext.com"/>
    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 (!NetworkStatus.IsInternetConnected())
        {
          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.Subject = subject;
        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);
        smtpClient.Dispose();
      }
      catch (System.Exception exception)
      {
        MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString());
      }
    }

    public static void SendEmail(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 (!NetworkStatus.IsInternetConnected())
        {
          MDTrace.WriteLine(LogLevel.DEBUG,"The internet is not connected.  Cannot send Email.");
          return;
        }
        MailMessage mailMessage = new MailMessage();
        mailMessage.From = new MailAddress(from);
        mailMessage.Body = message;
        mailMessage.Subject = subject;
        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);
        smtpClient.Dispose();
      }
      catch (System.Exception exception)
      {
        MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString());
      }
    }



  }
}
