The Email API provides functionalities to connect with users' mailboxes, authenticate via OAuth2, check for new emails since a given timestamp, and calculate the hypothetical cost of processing emails using a model.
- Authentication: Uses OAuth2 to authenticate users with their email providers (Google and Microsoft).
- Email Retrieval: Fetches emails since a given timestamp.
- The user initiates an OAuth2 flow by providing their email.
- Once authenticated, the user can query for new emails since a timestamp.
- OAuth2 for Authentication: Chose OAuth2 due to its widespread adoption and security. It also provides a seamless experience for users.
- Express.js Framework: Used Express.js for its simplicity, performance, and extensive middleware support.
- Modular Structure: Adopted a modular directory structure to separate concerns, making the codebase scalable and maintainable.
- Node.js (v13.2.0 or above)
- A Google Developer account with OAuth2 credentials set up.
- A Microsoft Azure account with OAuth2 credentials set up.
- Clone the repository:
```bash git clone https://github.com/umer-shaikhh/email-api.git cd email-api ```
- Install the dependencies:
```bash npm install ```
- Create a
.env
file in the root directory and add your OAuth2 credentials:
```env GOOGLE_CLIENT_ID=YOUR_GOOGLE_CLIENT_ID GOOGLE_CLIENT_SECRET=YOUR_GOOGLE_CLIENT_SECRET MICROSOFT_CLIENT_ID=YOUR_MICROSOFT_CLIENT_ID MICROSOFT_CLIENT_SECRET=YOUR_MICROSOFT_CLIENT_SECRET SESSION_SECRET=some_random_secret ```
- Start the server:
```bash npm start ```
The server will start on http://localhost:3000
.
To authenticate with an email provider, use the /auth/connect
endpoint:
``` GET /auth/connect?email=[email protected] ```
The server will redirect to the appropriate OAuth flow based on the email domain.
To check if a user has received new emails since a given timestamp:
``` GET /email/search?since=timestamp ```
To calculate the cost of processing emails from the last 24 hours:
``` GET /email/cost ```
To run the test suite:
```bash npm test ```