euporter🎃
euporter🎃
CC#
Created by euporter🎃 on 11/15/2024 in #help
Problem with Pop3Client
Hey, I'm making a post service/ smt like that app for my school asignment. I'm having issues, because the login credentials that work for sending emails (MailKit) dont work for retrieving them somehow (Pop3Client).
// MailPage.xaml.cs
public void LoadMail()
{
var client = new Pop3Client();
client.Connect("pop.gmail.com", 995, true);
client.Authenticate(Email, Password); // throws: MailKit.Security.AuthenticationException: „Authentication failed.”
var count = client.GetMessageCount();
StackPanel mailPanel = MailPanel.Children.OfType<StackPanel>().First();
mailPanel.Children.Clear();
foreach(MimeMessage message in client.GetMessages(Enumerable.Range(0, 100).ToList()))
{
mailPanel.Children.Add(new Label { Content = message.Subject });
}
}
// LoginPage.xaml.cs
// Works perfectly, it has the exact same credentials
public static bool Authenticate(string server, int port, string username, string password, bool enableSsl)
{
SmtpClient client=null;
try
{
client = new SmtpClient();
var options = enableSsl ? SecureSocketOptions.StartTls : SecureSocketOptions.Auto;
client.Connect(server, port, options);
client.Authenticate(username, password);
client.Disconnect(true);
return true;
}
catch(Exception ex)
{
Debug.WriteLine("Authentication failed");
return false;
}
finally
{
if (client != null)
{
client.Dispose();
}

}
}
// MailPage.xaml.cs
public void LoadMail()
{
var client = new Pop3Client();
client.Connect("pop.gmail.com", 995, true);
client.Authenticate(Email, Password); // throws: MailKit.Security.AuthenticationException: „Authentication failed.”
var count = client.GetMessageCount();
StackPanel mailPanel = MailPanel.Children.OfType<StackPanel>().First();
mailPanel.Children.Clear();
foreach(MimeMessage message in client.GetMessages(Enumerable.Range(0, 100).ToList()))
{
mailPanel.Children.Add(new Label { Content = message.Subject });
}
}
// LoginPage.xaml.cs
// Works perfectly, it has the exact same credentials
public static bool Authenticate(string server, int port, string username, string password, bool enableSsl)
{
SmtpClient client=null;
try
{
client = new SmtpClient();
var options = enableSsl ? SecureSocketOptions.StartTls : SecureSocketOptions.Auto;
client.Connect(server, port, options);
client.Authenticate(username, password);
client.Disconnect(true);
return true;
}
catch(Exception ex)
{
Debug.WriteLine("Authentication failed");
return false;
}
finally
{
if (client != null)
{
client.Dispose();
}

}
}
Please help, i tried creating a new app password and everything, i have no idea how to make it work.
18 replies