Skip to content
This repository has been archived by the owner on Jan 16, 2025. It is now read-only.
/ email-engine Public archive

this is an email engine, which uses outlook oAuth2.0 to login and it uses the elastic search for the email sync

Notifications You must be signed in to change notification settings

Ankush-Hegde/email-engine

Repository files navigation

clone the repo

git clone "https://github.com/Ankush-Hegde/email-engine"

cd email-engine

to start the project

  1. start the xamp/sql server

  2. create the database email_engine

  3. migrate the database using php artisan migrate command

  4. change .env.example to .env

  5. run the following to generate the encryption key php artisan key:generate.

  6. start and then set up elastic search by using this commandphp artisan elasticsearch:setup

  7. start the server using php artisan start command

  8. navigate to localhost:8000 in browser and click on the outlook oauth

API

1. generate_url

gethttp://localhost:8000/api/v1/oauth/outlook/generate_url

response

{
    "redirect_uri": "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=2fc8eb46-76ba-4ca4-b70f-aed8d77e3a56&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fapi%2Fv1%2Foauth%2Foutlook%2Fcallback&scope=openid+offline_access+profile+email+Mail.ReadWrite+Mail.Read+Mail.Send"
}

2. callback

gethttp://localhost:8000/api/v1/oauth/outlook/callback?code=E.V533_BW4.4.D.73cf-32-67-7a-ef0

response

this will return view
Registration Manage Mails
registeration-git manage-mails-git

3. fetchMail from the microsoft graph api

posthttp://localhost:8000/api/v1/email/fetch
body json

{
    "email" : "[email protected]" // used as a session for the simplicity
}

response

[
    {
        "_index": "emails",
        "_id": "AQMkADAwATM3ZmYAZS02ZTLTAwCgBGAAADMAO-kHNvAU_QWj_itP_POwcA4KYOSSojDkC6diOE8kTG-gAAAgEJAAAA4KYOSSojDkC6diOE8kTG-gABGOFl4gAAAA==",
        "_score": 0.18232156,
        "_source": {
            "user_id": 2,
            "subject": "Meeting Reminder",
            "body": "This is a reminder for our meeting.",
            "from": "[email protected]",
            "to": [
                {
                    "emailAddress": "[email protected]"
                }
            ],
            "cc": [],
            "bcc": [],
            "is_read": true,
            "received_date": "2024-12-08T12:47:45Z",
            "sent_date": "2024-12-08T12:47:44Z"
        }
    },
    {
        "_index": "emails",
        "_id": "AQMkADAwATM3ZmYACLTAwCgBGAAADMAO-kHNvAU_QWj_itP_POwcA4KYOSSojDkC6diOE8kTG-gAAAgEJAAAA4KYOSSojDkC6diOE8kTG-gABGOFl4QAAAA==",
        "_score": 0.18232156,
        "_source": {
            "user_id": 2,
            "subject": "Meeting Reminder",
            "body": "This is a reminder for our meeting.",
            "from": "[email protected]",
            "to": [
                {
                    "emailAddress": "[email protected]"
                }
            ],
            "cc": [],
            "bcc": [],
            "is_read": true,
            "received_date": "2024-12-08T12:47:19Z",
            "sent_date": "2024-12-08T12:47:19Z"
        }
    }
]

fetch-email-git

4. send Mail

posthttp://localhost:8000/api/v1/email/send
body

{
    "email": "[email protected]",
    "subject": "test email",
    "body": "success!!",
    "toRecipients": ["[email protected]"]
}

response

{
    "message": "Email sent successfully"
}
Send-mail Send-Success
send-email sent-success-git

DB design

as of the requirements,

  1. need to have user_table, Oauth_table where Oauth_table structure is
| :---: | :---: |
| id | int |
| user_id | int |
| provider_type | (google, microsoft) |
| access_token | string |
| refresh_token | string |
| expair_in | dateTime |

we need to link oAuth table to user table with local user_id
NOTE: as of now, everything is stored in the user table which need to be corrected

middleware

we need to have session middleware, where session will be having the type to differenciate the outlook auth and the google auth, now lets assume that everything is hapaning only in the outlook email

TASKS:

[startedOn:07/12/2024] - [endedOn:09/12/2024]

  1. db elastic search -> SUCCESS!! [startedOn:07/12/2024] - [endedOn:07/12/2024]
  2. api using oauth -> SUCCESS!! [startedOn:08/12/2024] - [endedOn:08/12/2024]
  3. Email Data Synchronization -> SUCCESS!! [startedOn:09/12/2024] - [endedOn:09/12/2024] we can improve it by automatically syncing the email
  4. scalability -> SUCCESS!! [startedOn:08/12/2024] - [endedOn:08/12/2024]
  5. best practic -> SUCCESS!! [startedOn:08/12/2024] - [endedOn:08/12/2024]
  6. Extensibility -> SUCCESS!! [startedOn:09/12/2024] - [endedOn:09/12/2024]
  7. Deliverables docker -> SUCCESS!! [startedOn:07/12/2024] - [endedOn:07/12/2024]

view updated project on :- https://github.com/Ankush-Hegde/email-engine

About

this is an email engine, which uses outlook oAuth2.0 to login and it uses the elastic search for the email sync

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages