コード例 #1
0
        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));
        }
コード例 #3
0
        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");
            }
        }