public Task AuthorizeAsync(string userName, string password, EmailService emailService = EmailService.Gmail)
        {
            _username     = userName;
            _password     = password;
            _emailService = emailService;

            return(Task.Run(async() =>
            {
                var emailServiceInfo = EmailServiceProvider.GetEmailServiceInfo(emailService);

                _imapClient = new ImapClient {
                    ServerCertificateValidationCallback = (s, c, h, e) => true
                };

                await _imapClient.ConnectAsync(emailServiceInfo.ImapHost, emailServiceInfo.ImapPort, true);

                await _imapClient.AuthenticateAsync(userName, password);
            }));
        }
        public Task SendMessageAsync(string from, string to, string message, IEnumerable <string> attachmentsPaths)
        {
            if (_smtpClient == null)
            {
                return(Task.Run(async() =>
                {
                    var emailServiceInfo = EmailServiceProvider.GetEmailServiceInfo(_emailService);

                    _smtpClient = new SmtpClient {
                        ServerCertificateValidationCallback = (s, c, h, e) => true
                    };

                    await _smtpClient.ConnectAsync(emailServiceInfo.SmtpHost, emailServiceInfo.SmtpPort, false);

                    await _smtpClient.AuthenticateAsync(_username, _password);

                    return SendMessageInternal(@from, to, message, attachmentsPaths);
                }));
            }

            return(SendMessageInternal(@from, to, message, attachmentsPaths));
        }