Skip to content

A service that sends and verify OTPs via mails and also can be used to send mails in any integrated service written in Django

Notifications You must be signed in to change notification settings

Noah-droid/email-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Email and OTP Service

This is a Django-based mail microservice that handles sending OTPs for verification and sending emails. It is designed to be integrated with other microservices, for various task purposes.

Features

  • Send OTPs to users via email.
  • Verify OTPs sent to users.
  • Send general emails.
  • Swagger documentation for all endpoints.

Requirements

  • Python 3.8+
  • Django 3.2+
  • Django REST framework
  • drf-yasg (for Swagger documentation)

Installation

  1. Clone the repository:

    git clone https://github.com/Noah-droid/email-service.git
    cd mail
  2. Create and activate a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
  3. Install the dependencies:

    pip install -r requirements.txt
  4. Configure the email settings in mail/settings.py:

    EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
    EMAIL_HOST = 'smtp.gmail.com'
    EMAIL_PORT = 587
    EMAIL_USE_TLS = True
    EMAIL_HOST_USER = '[email protected]'
    EMAIL_HOST_PASSWORD = 'your_email_password'
    DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
  5. Apply migrations:

    python manage.py makemigrations
    python manage.py migrate
  6. Run the development server:

    python manage.py runserver 0.0.0.0:8594

Endpoints

Send OTP

  • URL: /service/send-otp/
  • Method: POST
  • Request Body:
    {
        "email": "[email protected]"
    }
  • Response:
    • 200 OK if the OTP is sent successfully.
    • 400 Bad Request if there is an error in the request.

Verify OTP

  • URL: /service/verify-otp/
  • Method: POST
  • Request Body:
    {
        "email": "[email protected]",
        "otp": "123456"
    }
  • Response:
    • 200 OK if the OTP is verified successfully.
    • 400 Bad Request if the OTP is invalid or expired.

Send Email

  • URL: /service/send-email/
  • Method: POST
  • Request Body:
    {
        "to_email": "[email protected]",
        "subject": "Email Subject",
        "message": "Email message content."
    }
  • Response:
    • 200 OK if the email is sent successfully.
    • 400 Bad Request if there is an error in the request.

Swagger Documentation

The Swagger UI for API documentation is available at:

About

A service that sends and verify OTPs via mails and also can be used to send mails in any integrated service written in Django

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published