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.
12 Replies
julian
julian3w ago
Read Gmail messages on other email clients using POP - Gmail Help
You can open your messages from Gmail in other mail clients that support POP, like Microsoft Outlook. Step 1: Make sure POP is the best way to read your emails IMAP and POP are both ways to rea
julian
julian3w ago
And is there a reason why you're using POP instead of SMTP?
euporter🎃
euporter🎃OP3w ago
i found this in the docs: AuthenticationException Authentication using the supplied credentials has failed. but it still doesnt explain why it failed nvm
julian
julian3w ago
@euporter🎃 Did you figure it out?
euporter🎃
euporter🎃OP3w ago
so i have to check some stuff on gmail? not sure, will check now
julian
julian3w ago
Mine is in Norwegian
julian
julian3w ago
No description
julian
julian3w ago
But POP isn't enabled by default "Status: POP is deactivated" So, try enabling that first, and see if that works.
euporter🎃
euporter🎃OP3w ago
works... all i had to do is read properly... i just grabbed the port and url and thought it would work, sorry for the waste of your time really thanks for the help
julian
julian3w ago
No worries! Also, you didn't waste my time! 😄 We are here to help each other 🙂
euporter🎃
euporter🎃OP3w ago
is there a way to mark this as solved?
julian
julian3w ago
I think you can right click on your thread as set is as closed
Want results from more Discord servers?
Add your server