MailSync Engine is a backend application that synchronizes email data from Outlook using OAuth2 authentication and stores it in MongoDB. The application is built with TypeScript, Node.js, and Express, and uses Docker for containerization.
- OAuth2 authentication with Outlook.
- Synchronizes email data from Outlook to MongoDB.
- RESTful API endpoints for authentication and email synchronization.
- Node.js
- Docker
- Docker Compose
- Outlook OAuth2 credentials
Clone the repo from the following:
git clone https://github.com/sammsulhoq/mailsync-engine
cd mailsync-engine
Create a .env
file in the root directory with the following content:
PORT=5000
OUTLOOK_CLIENT_ID=your_outlook_client_id
OUTLOOK_CLIENT_SECRET=your_outlook_client_secret
CALLBACK_URL=http://localhost:5000/api/auth/callback
MONGO_URI=mongodb://mongo:27017/mailsync
Replace your_outlook_client_id
and your_outlook_client_secret
with your actual Outlook OAuth client ID and client secret.
Use Docker Compose to build and start the application:
docker-compose up --build
This command will:
- Build the Node.js application and compile TypeScript files.
- Start the Node.js application and MongoDB services.
Once the containers are up and running, you can access the application at http://localhost:5000
Initiates the OAuth2 login process and generates a URL for users to log in with their Outlook account.
POST /api/auth/login
Response: Redirects to the Outlook login page.
Handles the callback from Outlook after a successful login, saves user details and access token, and returns a JSON response.
GET /api/auth/callback?code=<auth_code>
Response:
{
"message": "Authentication successful",
"user": {
"email": "[email protected]",
"outlookId": "outlook_id",
"localId": "local_id"
}
}
Synchronizes email data from Outlook to the local MongoDB database for the authenticated user.
Request:
POST /api/sync/emails
{
"userId": "local_user_id"
}
Response:
200 OK
Email data synchronized successfully
If you prefer running the application locally without Docker, follow these steps:
- Install Dependencies:
npm install
- Compile TypeScript:
npm run build
- Start Application:
npm start
Make sure you have a running MongoDB instance and update the MONGO_URI
in the .env
file accordingly.
You can use tools like Postman or cURL to test the API endpoints.