Code as given below
objImap.SSLConfiguration.EnabledSslProtocols = SslProtocols.Tls12; objImap.ConnectSSL("outlook.office365.com"); objImap.UseBestLogin("emailaddress", "password"); objImap.SelectInbox(); List<long> uids = objImap.Search(Flag.All); foreach (long uid in uids) { var eml = objImap.GetMessageByUID(uid); IMail objEmail = new MailBuilder() .CreateFromEml(eml); foreach (MimeData mime in objEmail.Attachments) { if (mime.ContentType == ContentType.ApplicationPdf) { string path = @"C:\Att\" + obj.EmailAddress + @"\"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } mime.Save(path + mime.SafeFileName); } } } objImap.Close();
Used TLS and credentials are correct still getting error 6B4D0003 NO AUTHENTICATE failed.
Your problem is not with connecting or SSL/TLS version. The error is clear: server rejects your credentials.
Most likely you are trying to use your primary password.
You either need to configure your Office365 to allow that, use OAuth or use application passwords.
First make sure IMAP is turned on for this account: https://www.limilabs.com/blog/office365-enable-imap-pop3-smtp
To use OAuth user flow: https://www.limilabs.com/blog/oauth2-office365-exchange-imap-pop3-smtp
To use OAuth password grant flow: https://www.limilabs.com/blog/oauth2-password-grant-office365-exchange-imap-pop3-smtp
To use OAuth client credential flow: https://www.limilabs.com/blog/oauth2-client-credential-flow-office365-exchange-imap-pop3-smtp
To use application passwords (no longer recommended): https://www.limilabs.com/blog/office365-app-passwords