Up to this point I was happily connecting to my gmail with the method similar to this one below:
public async Task<IEnumerable<MimeMessage>> GetMessagesAsync()
{
using var imapClient = new MailKit.Net.Imap.ImapClient();
var secureSocketOptions = SecureSocketOptions.Auto;
if (useSsl) secureSocketOptions = SecureSocketOptions.SslOnConnect;
await imapClient.ConnectAsync(host, port, secureSocketOptions);
await imapClient.AuthenticateAsync(login, password);
await imapClient.Inbox.OpenAsync(FolderAccess.ReadOnly);
var uids = await imapClient.Inbox.SearchAsync(SearchQuery.All);
var messages = new List<MimeMessage>();
foreach (var uid in uids)
{
messages.Add(await imapClient.Inbox.GetMessageAsync(uid));
}
imapClient.Disconnect(true);
return messages;
}
After May 30, 2022 this is no longer possible as support for 'less secure apps' was
- Simply use your gmail username (
[email protected]
) and the password generated in yourc#
application.