public new async Task <bool> ConnectAsync()
        {
            await base.ConnectAsync();

            var result = await ExecuteCommand(SmtpCommands.EHLO(Host));

            return(result.Contains(SmtpResponse.ACTION_OK));
        }
Пример #2
0
        public async Task <bool> AuthenticateAsync(string userName, string password)
        {
            if (!UseSSL)
            {
                await UpgradeToSecureConnection();
            }
            await ExecuteCommand(SmtpCommands.EHLO(Host));
            await ExecuteCommand(SmtpCommands.AUTHLOGIN());
            await ExecuteCommand($"{ ToBase64(userName)}\r\n");

            var result = await ExecuteCommand($"{ToBase64(password)}\r\n");

            return(result.Contains(SmtpResponse.AUTHENTICATION_SUCCESS));
        }
        private async Task <bool> UpgradeToSecureConnection()
        {
            var upgradeResult = await ExecuteCommand(SmtpCommands.STARTTLS());

            if (upgradeResult.Contains(SmtpResponse.SERVICE_READY))
            {
                UseSSL  = true;
                _stream = GetStream();
                return(true);
            }
            else
            {
                throw new Exception("Could not upgrade SMTP non SSL connection using STARTTLS handshake");
            }
        }