Код: Выделить всё
string statCommand = $"STAT\r\n";
SendCommand(sslStream, statCommand);
Код: Выделить всё
string pop3Server = "pop3.test.corp.ae"; // Replace with your POP3 server
int pop3Port = 995; // SSL port
string username = "testmail@test.com";
string password = "1234ere";
// Path to the client certificate
string certificatePath = @"D:\test\test.crt";
string certificatePassword = "";
// System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
// Pop3Client pop3Client = new Pop3Client();
//pop3Client.Connect(pop3Server, pop3Port, true);
//pop3Client.Authenticate(username, password);
// Load the client certificate
X509Certificate2 clientCertificate = new X509Certificate2(certificatePath);//certificatePassword);
// Connect to the POP3 server
using (TcpClient client = new TcpClient(pop3Server, pop3Port))
using (SslStream sslStream = new SslStream(
client.GetStream(),
false,
new RemoteCertificateValidationCallback(ValidateServerCertificate),
null))
{
// Authenticate using SSL with the client certificate
sslStream.AuthenticateAsClient(pop3Server, new X509CertificateCollection { clientCertificate }, System.Security.Authentication.SslProtocols.Tls12, false);
// Send POP3 commands to authenticate and retrieve emails
string loginCommand = $"USER {username}\r\n";
SendCommand(sslStream, loginCommand);
string passCommand = $"PASS {password}\r\n";
SendCommand(sslStream, passCommand);
}
static void SendCommand(SslStream sslStream, string command)
{
byte[] buffer = Encoding.ASCII.GetBytes(command);
sslStream.Write(buffer, 0, buffer.Length);
sslStream.Flush();
// Read server response (if needed)
byte[] responseBuffer = new byte[2048];
int bytesRead = sslStream.Read(responseBuffer, 0, responseBuffer.Length);
string response = Encoding.ASCII.GetString(responseBuffer, 0, bytesRead);
Console.WriteLine(response);
}
Возникла проблема с интерполяцией строк, мне пришлось заменить @ на $...
Итак, теперь
Код: Выделить всё
string loginCommand = $"USER {username}\r\n";
и для строки passCommand = $"PASS {password}\r\n";
Я получаю ответ +ОК
но для строки statCommand = $"STAT\r\n";
Я получение ответа в виде -ERR Ошибка входа в систему: неизвестное имя пользователя или неверный пароль
Подробнее здесь: https://stackoverflow.com/questions/790 ... -in-vs2022
Мобильная версия