IMAP Login

Copper Contributor

Hello everyone
I am ROR developer working on a application in which I have to read emails received on this office365 account via IMAP but currently I am not able to login via IMAP (did logged in once about 5 to 6 months ago by disabling "security defaults", but this thing is not working now).
I don't have enough technical knowledge of Azure or Exchange I just want to login remotely using IMAP and read emails. I went through the docs but at the end, I was just confused.
Preferably I want to login without following OAUTH flow if it is possible on today's date (26 sept 23) but if there is no way forward without OAUTH then guide me to login using OAUTH.
Please tell what i need enable/disable , 2FA, security defaults anything else. as It is urgent. thank you.

3 Replies

Hi @bradsalvin,

1. Azure App Registration: To access your Office 365 emails via IMAP with OAuth, you'll first need to set up an Azure App Registration. This essentially creates a connection between your application and Office 365. You can do this by logging into the Azure portal, navigating to Azure Active Directory, and then creating a new registration for your app.

2. Authentication Configuration: Within your App Registration, go to the "Authentication" section. Here, you'll set up how your app handles authentication. Add a new platform (typically "Web") and specify a redirect URI where your app will receive authentication responses.

3. API Permissions: Now, head over to the "API permissions" section. This is where you define what your app can do within Office 365. You'll likely want to add permissions for accessing emails, such as Mail.Read.

4. Authentication Flow: In your application's code, implement the OAuth 2.0 authentication flow. This is where your app will request an access token that proves it has permission to access your Office 365 account. There are many libraries and resources available to help with this step, depending on your programming language and platform.

5. IMAP Configuration: With the access token obtained in step 4, you can now authenticate with the IMAP server. The exact steps here depend on the library or code you're using. You'll need to provide the access token as part of the authentication process.

6. Security Defaults and 2FA: Keep in mind that Office 365 often enforces security measures like security defaults and two-factor authentication (2FA). This is a good thing for security, but it can sometimes affect your OAuth flow. You may need to work with your IT team to adjust these settings if they're causing issues.

For more detailed steps and examples specific to your development environment, I recommend checking out the official documentation:

While OAuth can seem complex, it's the recommended and secure way to access Office 365 services. It's worth the effort to set it up properly to protect your email and data.

Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.


If the post was useful in other ways, please consider giving it Like.


Kindest regards,


Leon Pavesic
(LinkedIn)

@LeonPavesic Thanks man for your reply but the Oauth flow is a bit lengthy and at the moment I don't really care which is more secure I just want to read emails from mailbox, surely I will migrate to the Oauth flow later on.
NOTE: Google terminated plain access via IMAP last year but we can enable 2FA and perform plain authentication using app password So I am looking for just something like this.Is there any way?

Hi @bradsalvin,

Microsoft is moving away from supporting plain authentication for IMAP. This is because plain authentication is not very secure, and it is more difficult to manage and troubleshoot.

However, there is a workaround that you can use to read emails from your Office 365 mailbox without OAuth. This workaround involves using an app password.

To generate an app password:

  1. Go to the My Account page in Office 365.
  2. Click Security Info.
    LeonPavesic_0-1695810957223.png

     

  3. Under App passwords, click Create a new app password.
    LeonPavesic_1-1695810993086.png

     

  4. Give your app password a name, and then click Create.
  5. Copy your app password and store it in a safe place.

Once you have generated an app password, you can use it to authenticate with the IMAP server. To do this, simply enter your email address and app password when prompted.

Here are the steps for configuring your IMAP client to use an app password:

  1. Open your IMAP client.
  2. Enter your email address and app password.
  3. Click Connect.


Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.


If the post was useful in other ways, please consider giving it Like.


Kindest regards,


Leon Pavesic