This guide explains how to set up tokens, configure environment variables, and use the utility functions for Gmail and Outlook integration in your Email Spam Report project.
- Go to Google Cloud Console.
- Create a new project.
- In your project, go to APIs & Services > Library.
- Search for "Gmail API" and enable it.
- Go to APIs & Services > Credentials.
- Click Create Credentials > OAuth client ID.
- Choose "Web application".
- Set the redirect URI (e.g.,
http://localhost:3000/api/oauth-callbackfor local, or your Vercel domain for production). - Save your Client ID and Client Secret.
- Use a tool like OAuth Playground or your own script to authorize your app and get a refresh token.
- Make sure to use the same redirect URI as in your credentials.
GMAIL_1_CLIENT_ID=your_client_id
GMAIL_1_CLIENT_SECRET=your_client_secret
GMAIL_1_REFRESH_TOKEN=your_refresh_token
GMAIL_REDIRECT_URI=your_redirect_uri
Repeat for additional Gmail accounts.
- Go to Azure Portal.
- Register a new application in Azure Active Directory > App registrations.
- Add permissions for
Mail.Readandoffline_access.
- Copy the Application (client) ID, Directory (tenant) ID, and generate a Client Secret.
- Set the redirect URI for your app (local and production).
- Use a tool or script to authorize your app and obtain a refresh token.
- The refresh token is tied to the redirect URI used during authorization.
OUTLOOK_CLIENT_ID=your_client_id
OUTLOOK_CLIENT_SECRET=your_client_secret
OUTLOOK_REFRESH_TOKEN=your_refresh_token
OUTLOOK_REDIRECT_URI=your_redirect_uri
OUTLOOK_TENANT_ID=your_tenant_id
OUTLOOK_INBOX_ID=your_inbox_folder_id
OUTLOOK_JUNK_ID=your_junk_folder_id
- Uses
googleapisto connect and check inbox, spam, and promotions. - Utility:
getGmailClientin/lib/utilsor/api/check-emails/route.ts.
- Uses Microsoft Graph API to check Inbox, Junk, and Promotions.
- Utility:
getOutlookAccessTokenandcheckOutlookInboxin/lib/outlookUtils.ts.
- Refresh tokens are tied to the redirect URI.
If you change the redirect URI (e.g., when moving to production), you must re-authorize and get a new refresh token. - Store tokens securely and never commit them to source control.
- The
/api/check-emailsendpoint uses these tokens to check deliverability for each provider. - Scheduled via Vercel cron job (see README).
- If you get authentication errors, check that your refresh token matches the redirect URI and client credentials.
- Ensure all required environment variables are set in Vercel for production.
- For configuring via azure use chrome or edge
You can use utility functions in /lib/outlookUtils.ts and /lib/utils.ts to help with setup tasks:
-
Get Outlook Folder IDs:
Use helper functions or scripts to list your Outlook folders and find the correctINBOXandJUNKfolder IDs for your account. -
Get Refresh Tokens:
Use provided scripts or instructions to run the OAuth flow and obtain refresh tokens for Gmail and Outlook. -
Testing Utilities:
You can use these utilities to verify your API credentials and tokens before deploying to production.