Coder Social home page Coder Social logo

multiemail / backend Goto Github PK

View Code? Open in Web Editor NEW
16.0 1.0 14.0 6.44 MB

Project to manage multiple emails at once with lots of customization. You can send and receive emails. Desktop notifications can be modified.

License: MIT License

TypeScript 74.43% JavaScript 25.31% Shell 0.13% Dockerfile 0.14%
hacktoberfest nodejs express mern mongodb mongoose rest restapi hacktoberfest-accepted

backend's Introduction

All Contributors

Technologies Used

  • ExpressJs
  • Mongoose
  • Typegoose
  • TypeScript
  • Passport

Features

  • Admin dashboard
  • User settings and or user dashboard
  • Send emails
  • Receive emails
  • Connections through other parties ie discord, twitter, facebook etc..

Run locally

You can setup the application on your local system by 2 methods

  • Docker
  • Manually

⚠️ If you are using unix operating system than prefix all bash commands with sudo

Create new directory and clone the repository

mkdir multi-email
cd multi-email
git clone https://github.com/MultiEmail/backend.git
cd backend

Using Docker

Prerequisite

  • Docker is installed on your local system
  • .env file wih all required variables (check environment variables mentioned below)

Run Server

docker compose --env-file ./.env up

To rebuild the image

docker compose --env-file ./.env up --build

Create admin user

List current running docker containers

docker ps

Output

CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS                                         NAMES
d07f06c78445   backend-api    "docker-entrypoint.s…"   46 minutes ago   Up 46 minutes   0.0.0.0:3001->3001/tcp, :::3001->3001/tcp     Server
91826c111b76   mongo:latest   "docker-entrypoint.s…"   52 minutes ago   Up 46 minutes   0.0.0.0:2717->27017/tcp, :::2717->27017/tcp   Database

now copy the CONTAINER ID of image/container backend-api and replace <container_id> in the below mentioned commands and execute them

# build and install the command line tool in docker container
docker exec <container_id> yarn build
docker exec <container_id> npm i -g .
# create new admin user in database in docker container
docker exec <container_id> multi-email-admin -e <email> -u <username> -p <password>

Extra's (Port forwarding for docker containers)

Container PORT (host) Port (container)
Server 3001 3001
MongoDB 2717 27017

if you want to access database inside docker container from host than use

mongosh --port 2717

or if you want to use mongodb compass than you can use this connection string

mongodb://localhost:2717/

Manually

Prerequisite

  • Latest Node js version
  • Yarn installed
  • Mongodb installed on local system
  • .env file wih all required variables (check environment variables mentioned below)

Install all the required dependencies

this project use Yarn as package manager

yarn install

Run the server

yarn dev

Create admin user

yarn build
npm i -g .
multi-email-admin -e <email> -u <username> -p <password>

Environment Variables

To run this project, you will need to add the following environment variables to your .env file

Name Description Example
BASE_URL Base URL on which server is running http://localhost:3001/api
DB_URI URI on which database is running mongodb://localhost:27017/multiemail
FRONTEND_URL URI on which frontend is running http://localhost:3000
GOOGLE_CLIENT_ID Client ID obtained while creating google oauth concent screen 758327950938-90jskrnp9b8d2e6ljpqrstd8fdl2k9fljkhchasnnrnj8.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET Client Secret obtained while creating google oauth concent screen GOCSPX-NL52LzLNzF6YGJxlAoeLAnGK-a6
GOOGLE_REDIRECT_URL URL on which user will be redirected after google oauth http://localhost:3001/api/auth/oauth/google/redirect
NODE_ENV What type of environment are you running this app in development
EMAIL_ID Which ID will be used for sending email [email protected]
EMAIL_PASSWORD Password of your email id mystrongpassword
EMAIL_SMTP Email SMTP host smtp.server.com
ACCESS_TOKEN_PRIVATE_KEY private RSA key which will be used to sign access token check .env.example file
ACCESS_TOKEN_PUBLIC_KEY public RSA key which will be used to verify access token check .env.example file
REFRESH_TOKEN_PRIVATE_KEY private RSA key which will be used to sign refresh token check .env.example file
REFRESH_TOKEN_PUBLIC_KEY public RSA key which will be used to verify refresh token check .env.example file

NOTEs

  • Your DB_URI must be mongodb://mongo_db:27017/multiemail if you are using docker
  • If you use gmail account as EMAIL_ID than you must enable 2FA for your google account and generate app password and use it as EMAIL_PASS

Resources for generating .env variables

  • You can get google credentials by following this guide
  • You can use crypto tools for generating RSA keys for access and refresh tokens
  • RSA keys must be 1024

Detailed docs

Wanna join the team?

Contributing

  • Contributions make the open source community such an amazing place to learn, inspire, and create.
  • Any contributions you make are truly appreciated.
  • Check out our contribution guidelines for more information.

License


This project is Licensed under the MIT License. Please go through the License atleast once before making your contribution.


Contributors ✨

Thanks goes to these wonderful people ❤:

Ayush Chugh
Ayush Chugh

🐛 🤔 🧑‍🏫 🛡️ 💻 🚧 📆 👀
Toby
Toby

💻 👀 🚧
shivam vishwakarma
shivam vishwakarma

📖 💻
Tharun K
Tharun K

📖 💻 🚇
Ayush
Ayush

🐛 🛡️ 🤔 🧑‍🏫 💻 🚧 📆 👀
James
James

💵 🤔 💼
AndrewDev
AndrewDev

🤔
Arpit Chugh
Arpit Chugh

📖
Drishit Mitra
Drishit Mitra

💻
João Mota
João Mota

💻
Shashank Bhat G S
Shashank Bhat G S

📖
Alberto Herrera Vargas
Alberto Herrera Vargas

💻
Vadym Yatsyuk
Vadym Yatsyuk

💻
Toby
Toby

🐛 🛡️ 🤔
yash jain
yash jain

💻
Bongani Gumbo
Bongani Gumbo

📖
Shikhar
Shikhar

💻
Add your contributions

This project follows the all-contributors specification. Contributions of any kind welcome!

backend's People

Contributors

aayushchugh avatar alberturria avatar allcontributors[bot] avatar areadrill avatar arpitchugh avatar bitofabyte avatar bonganibg avatar developer-diganta avatar drishit96 avatar is-it-ayush avatar madhvik007 avatar renovate[bot] avatar shashankbhatgs avatar shikhar13012001 avatar shivamvishwakarm avatar tharun634 avatar vadimdez avatar yashjain2409 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

backend's Issues

The Email Retrieve, Compose & Send Routes

Description

These are the requested features (routes):

  • /mail/retrieve/:service/:amt (GET) : Fetched the amt number of last emails from the service. If amt is not provided. The default amt would be 100.
  • /mail/drafts/:service (GET) : Returns all the draft emails, their associated id's with their associated service.

Note: If the service is not provided, it returns all draft mails and their associated id's.

  • /mail/edit/:id (PATCH) : Updates the content of the given email that has the following id
  • /mail/drafts (POST) : Saves a draft email by giving it an id and saves the service with it.
  • /mail/send/:id (GET) : Sends the mail that has the id if it exists. Every saved draft email with have a id and a service saved.

Here the service could be any mail service that has a Public API and work's via a token. Some considerations: GMail, Hotmail, Yahoo Mail, Etc.

Anything else?

Feel free to add any other routes that you might think would be necessary.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Warning

These dependencies are deprecated:

Datasource Name Replacement PR?
npm @types/axios Unavailable
npm @types/dotenv Unavailable
npm eslint-plugin-node Available

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): replace dependency eslint-plugin-node with eslint-plugin-n 14.0.0
  • chore(deps): update dependency @types/bcrypt to v5.0.2
  • chore(deps): update dependency @types/cors to v2.8.17
  • chore(deps): update dependency @types/express to v4.17.21
  • chore(deps): update dependency supertest to v6.3.4
  • chore(deps): update dependency ts-node to v10.9.2
  • fix(deps): update dependency body-parser to v1.20.3
  • chore(deps): update dependency eslint to v8.57.1
  • chore(deps): update dependency eslint-plugin-no-secrets to v0.9.1
  • chore(deps): update dependency eslint-plugin-no-unsanitized to v4.1.0
  • chore(deps): update dependency mongodb-memory-server to v8.16.1
  • chore(deps): update dependency typedoc to v0.26.7
  • fix(deps): update dependency @typegoose/typegoose to v10.5.0
  • fix(deps): update dependency @types/lodash to v4.17.7
  • fix(deps): update dependency axios to v1.7.7
  • fix(deps): update dependency bcrypt to v5.1.1
  • fix(deps): update dependency dotenv to v16.4.5
  • fix(deps): update dependency express to v4.21.0
  • fix(deps): update dependency express-rate-limit to v6.11.2
  • fix(deps): update dependency http-status-codes to v2.3.0
  • fix(deps): update dependency isomorphic-dompurify to v1.13.0
  • fix(deps): update dependency mongoose to v7.8.1
  • fix(deps): update dependency nodemailer to v6.9.15 (nodemailer, @types/nodemailer)
  • fix(deps): update dependency pino to v8.21.0
  • fix(deps): update dependency pino-pretty to v10.3.1
  • fix(deps): update dependency yargs to v17.7.2
  • fix(deps): update dependency zod to v3.23.8
  • chore(deps): update actions/checkout action to v4
  • chore(deps): update actions/setup-node action to v4
  • chore(deps): update commitlint monorepo to v19 (major) (@commitlint/cli, @commitlint/config-conventional, commitlint)
  • chore(deps): update dependency eslint to v9
  • chore(deps): update dependency eslint-config-prettier to v9
  • chore(deps): update dependency eslint-plugin-no-secrets to v1
  • chore(deps): update dependency eslint-plugin-prettier to v5
  • chore(deps): update dependency eslint-plugin-sonarjs to v2
  • chore(deps): update dependency husky to v9
  • chore(deps): update dependency lint-staged to v15
  • chore(deps): update dependency mongodb-memory-server to v10
  • chore(deps): update dependency prettier to v3
  • chore(deps): update dependency prettier-eslint to v16
  • chore(deps): update dependency supertest to v7
  • chore(deps): update dependency typescript to v5
  • chore(deps): update node.js to v20
  • chore(deps): update typescript-eslint monorepo to v8 (major) (@typescript-eslint/eslint-plugin, @typescript-eslint/parser)
  • fix(deps): update dependency @typegoose/typegoose to v12
  • fix(deps): update dependency express-rate-limit to v7
  • fix(deps): update dependency helmet to v7
  • fix(deps): update dependency isomorphic-dompurify to v2
  • fix(deps): update dependency jsonwebtoken to v9 (jsonwebtoken, @types/jsonwebtoken)
  • fix(deps): update dependency mongoose to v8
  • fix(deps): update dependency nodemon to v3
  • fix(deps): update dependency pino to v9
  • fix(deps): update dependency pino-pretty to v11
  • 🔐 Create all rate-limited PRs at once 🔐

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

docker-compose
docker-compose.yml
dockerfile
Dockerfile
  • node 16-alpine
github-actions
.github/workflows/deploy-docs.yml
  • actions/checkout v3
  • JamesIves/github-pages-deploy-action v4
.github/workflows/tests.yml
  • actions/checkout v3
  • actions/setup-node v3
npm
package.json
  • @typegoose/typegoose ^10.0.0
  • @types/axios ^0.14.0
  • @types/lodash ^4.14.186
  • @types/nodemailer ^6.4.6
  • axios ^1.1.2
  • bcrypt ^5.0.1
  • body-parser ^1.20.0
  • cors ^2.8.5
  • dotenv ^16.0.2
  • express ^4.18.1
  • express-rate-limit ^6.6.0
  • helmet ^6.0.0
  • http-status-codes ^2.2.0
  • isomorphic-dompurify ^1.0.0
  • jsonwebtoken ^8.5.1
  • lodash ^4.17.21
  • mongoose ^7.0.0
  • nodemailer ^6.8.0
  • nodemon ^2.0.20
  • pino ^8.6.0
  • pino-pretty ^10.0.0
  • qs ^6.11.0
  • yargs ^17.6.0
  • zod ^3.19.1
  • @commitlint/cli 17.4.4
  • @commitlint/config-conventional 17.4.4
  • @types/bcrypt 5.0.0
  • @types/cors 2.8.14
  • @types/dotenv 8.2.0
  • @types/express 4.17.18
  • @types/jsonwebtoken 9.0.0
  • @typescript-eslint/eslint-plugin 5.62.0
  • @typescript-eslint/parser 5.62.0
  • add 2.0.6
  • all-contributors-cli 6.24.0
  • commitlint 17.4.4
  • cz-conventional-changelog 3.3.0
  • eslint 8.50.0
  • eslint-config-google 0.14.0
  • eslint-config-prettier 8.10.0
  • eslint-import-resolver-typescript 3.5.3
  • eslint-plugin-import 2.27.5
  • eslint-plugin-jsonc 2.6.0
  • eslint-plugin-no-secrets 0.8.9
  • eslint-plugin-no-unsanitized 4.0.2
  • eslint-plugin-node 11.1.0
  • eslint-plugin-pii 1.0.2
  • eslint-plugin-prettier 4.2.1
  • eslint-plugin-sonarjs 0.18.0
  • husky 8.0.3
  • jest 29.7.0
  • lint-staged ^13.0.3
  • mongodb-memory-server 8.15.1
  • prettier 2.8.8
  • prettier-eslint 15.0.1
  • supertest 6.3.3
  • ts-jest 29.0.5
  • ts-node 10.9.1
  • ts-node-dev 2.0.0
  • typedoc 0.23.26
  • typescript 4.9.5

  • Check this box to trigger a request for Renovate to run again on this repository

[REFACTOR] :recycle: Seprate admin action's in it's own endpoint.

Description

Refactor the code to differentiate between /admin and /user's endpoints. All performable API calls for admin can have thier own endpoint for better security and management. It would also avoid the confusion for future Developer's.

Current Behaviour (as of currently available endpoint's):

  • /users/markverified/:id (PATCH) - Marks a user verified.
  • /users/:id (DELETE) - Delete's a user.

Expected Behaviour

  • /admin/users/markverified/:id (PATCH) - Marks a user verified.
  • /admin/users/:id (DELETE) - Delete's a user.
    . . .

[FEAT] :sparkles: Send marketing emails

Description

Admin should be able to send marketing emails to all the users in which receiveMarketingEmails is true

email content will be sent in html type

  • create a new model named marketingEmails with following fields
    • Subject (subject of the email)
    • users (users to which the email is sent)
  • Create new route POST /api/marketing

Anything else?

No response

[FEAT] :sparkles: Searching and filters while fetching emails from gmail

Description

These queries will be implemented with this issue

  • q Only return labels matching the specified query. Supports the same query format as the Gmail search box. For example, "from:[email protected] rfc822msgid:[email protected] is:unread". Parameter cannot be used when accessing the api using the gmail.metadata scope.
  • includeSpamTrash Include emails from SPAM and TRASH
  • labelIds only return emails with specific labels

Anything else?

https://developers.google.com/gmail/api/reference/rest/v1/users.messages/list

[BUG] :bug: We should not be able to connect same google/gmail account

Current Behaviour

If we connect same google account than it will create new object inside services array of user document in database

image

as you see there are 2 same emails as two different accounts

Expected Behaviour

There should be a validation that same account can't be added again and user should be redirected to frontend
application

Steps To Reproduce

  1. signup with new account
  2. connect a google account eg: [email protected]
  3. again connect same google account which is [email protected]
  4. now see that 2 accounts with same email are added to connected_services array in user document

Anything else?

Add if condition validation here

[FEAT] :sparkles: Delete user

Description

create new route DELETE /admin/users/:id by which admin will be able to delete user

Anything else?

write logic in user.controller.ts

[REFACTOR] :recycle: `deserializeUser` middleware should only be used for necessary routes

Description

currently deserializeUser middleware is running on all the routes but It should run only where it is needed
like we don't need it to run on login and signup but currently It is applied on all the requests

refactor the code so that deserializeUser middleware only runs on necessary routes like

  • PATCH /users/:id
  • /auth/logout

Anything else?

No response

[BUG] :bug: Emails should not be send in `test` environment

Current Behaviour

When we run yarn test command nodemailer send a email

Expected Behaviour

nodemailer should not send emails in test environment

Steps To Reproduce

  1. use yarn test command

Anything else?

We can add new if condition in email.util.ts at sendEmail function that will just return if current node environment is
test

[TEST] :test_tube: Writing Test's for /uesrs endpoint.

Description

Description

Writing test's for user's endpoint to validate all /users endpoints.

Covering Endpoints

  • /users
  • /users/:id (DELETE) - Delete User
  • /users/markverified/:id (PATCH) - Mark a user verified.
  • /users/:id (PATCH) - Update User

Anything else?

No response

[FEAT] :sparkles: Create admin user from command line

Description

We can't create a rest api endpoint for creating admin user because if we do than anyone can use that endpoint to create
admin user for them

We should implement a command that will run in terminal which will create a new user in database with role admin

example command:-

admin -e <email> -p <password>

Anything else?

I have already implemented this in another project you can get reference of code from here:-
https://github.com/shriproperty/server/blob/dev/bin/index.ts
https://github.com/shriproperty/server/blob/dev/package.json#L12-L14

Create issue template for no template

Description

If we create a new issue than we have to follow a template but if any issue don't satisfy the template than there should be
a template which will not contain any pre defined headings, labels, etc..

eg:- if we create a issue Configure Eslint than it will not fall into any category i.e.

  • Enhancement
  • Refactor
  • Bug
  • Security
  • Docs

so there should be a template which will be empty so that user can write whatever they want

Anything else?

No response

[DOCS] : Link License and Contributing.md to ReadMe

Description

Is your feature request related to a problem? Please describe.

Improving the docs by adding the LICENSE and contributing.md links to the ReadMe file.

Describe the solution you'd like

I would like to add the links of LICENSE and Contributing.md at the bottom of the readme file so as to make the readme more structured.

Anything else?

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.