Email Reader
This project is a console application written in C# that reads emails from a specified mailbox and folder using Microsoft Graph API. The application authenticates using Azure Identity and retrieves messages based on the provided command-line arguments.
- Authenticate using Azure Device Code Flow
- Read emails from a specified mailbox and folder
- Display email details such as sender, recipients, subject, and body
- .NET SDK
- Azure subscription and Azure AD app registration
- Microsoft Graph API permissions:
User.ReadandMail.Read
-
Clone the repository:
git clone <repository-url> cd <repository-directory>
-
Set up Azure AD app registration:
- Register an app in Azure AD and note down the
Client IDandTenant ID. - Grant the app
User.ReadandMail.Readpermissions.
- Register an app in Azure AD and note down the
-
Set environment variables:
export CLIENT_ID=<your-client-id> export TENANT_ID=<your-tenant-id>
Run the application with the following command:
dotnet run -- --mailbox <mailbox-address> --folder <folder-name> --messages <message-count>--mailbox: The email address of the mailbox to read from (default: "me" for the authenticated user)--folder: The name of the folder to read emails from (default: "Inbox")--messages: The number of messages to read (default: 10)
dotnet run -- --mailbox user@example.com --folder Inbox --messages 5- Authentication: The application uses
DeviceCodeCredentialfor authentication, which prompts the user to authenticate using a device code. - Graph Client: An instance of
GraphServiceClientis created using the authenticated credential. - Email Retrieval: Emails are fetched from the specified folder and details such as sender, recipients, subject, and body are displayed.
- If
CLIENT_IDorTENANT_IDenvironment variables are not set, the application will exit with code 3. - If invalid command-line arguments are provided, the application will display an error message and exit with code 1.
- If the folder is not found, the application will display an error message and exit with code 2.
- Microsoft.Graph
- Azure.Identity
- Microsoft.Identity.Client
This project is licensed under the MIT License.