using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MailKit.Net.Smtp;
using MailKit.Security;
using MimeKit;

namespace AssemblyDemo
{
    public class MailClient
    {

        public string userEmail
        { private get; set; }
        
        public string password
        { private get; set; }
        
        public string userName
        { private get; set; }
        
        public string subject
        { private get; set; }
        
        public string body
        { private get; set; }

        private MailRecipient to;

        public int setRecipient( string name, string address )
        {
            to = new MailRecipient();
            this.to.name = name;
            this.to.address = address;
            return 1;
        }

        public int sendMail()
        {
            var message = new MimeMessage();            
            message.From.Add(new MailboxAddress(userName, userEmail));
            message.To.Add(new MailboxAddress(to.name, to.address));
            message.Subject = subject;
            message.Body = new TextPart("plain") { Text = body };
            using (var client = new SmtpClient())
            {
                client.ServerCertificateValidationCallback = (s, c, h, e) => true;
                client.Connect("smtp.gmail.com", 465, SecureSocketOptions.SslOnConnect);
                client.Authenticate(userEmail,password);
                client.Send(message);
                client.Disconnect(true);
            }
            return 1;
        }
    }

    public class MailRecipient
    {
        public string address
        { get; set; }
        
        public string name
        { get; set; }
        
    }
    
    
}
