I'm trying to read an email from my mailbox using the MailKit library. Unfortunately the program throws this MailKit.Security.AuthenticationException: 'LOGIN failed.'
The credentials match (I tried to log in through the browser)
I'm trying to read an email from my mailbox using the MailKit library. Unfortunately the program throws this
MailKit.Security.AuthenticationException: 'LOGIN failed.'
I would be grateful for any help, I don't know what to do. I googled, tried this
client.Connect(
"
imap.outlook.com"
,
993
, SecureSocketOptions.None); But nothing came up when I changed
SecureSocketOptions to
Auto the same exception was thrown
My code:
using
(
var
client =
new
ImapClient())
using
(
var
cancel =
new
CancellationTokenSource())
client.Connect(
"
imap.outlook.com"
,
993
,
true
);
client.Authenticate(
"
mail@test.cz"
,
"
password"
, cancel.Token);
var
inbox = client.Inbox;
inbox.Open(FolderAccess.ReadOnly, cancel.Token);
Console.WriteLine(
"
Total messages: {0}"
, inbox.Count);
Console.WriteLine(
"
Recent messages: {0}"
, inbox.Recent);
for
(
int
i =
0
; i < inbox.Count; i++)
var
message = inbox.GetMessage(i, cancel.Token);
Console.WriteLine(
"
Subject: {0}"
, message.Subject);
var
query = SearchQuery.DeliveredAfter(DateTime.Parse(
"
2013-01-12"
))
.And(SearchQuery.SubjectContains(
"
MailKit"
))
.And(SearchQuery.Seen);
foreach
(
var
uid
in
inbox.Search(query, cancel.Token))
var
message = inbox.GetMessage(uid, cancel.Token);
Console.WriteLine(
"
[match] {0}: {1}"
, uid, message.Subject);
client.Disconnect(
true
, cancel.Token);
What I have tried:
Checked the credentials in Browser, switched Options in Client
You have to enable the 2 factor authentication on your email account, then create an app password and use
this password in your program.
Check this link "
Using app passwords with apps that don't support two-step verification
".
Read the question carefully.
Understand that English isn't everyone's first language so be lenient of bad
spelling and grammar.
If a question is poorly phrased then either ask for clarification, ignore it, or
edit the question
and fix the problem. Insults are not welcome.
Don't tell someone to read the manual. Chances are they have and don't get it.
Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.