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.
- Send OTPs to users via email.
- Verify OTPs sent to users.
- Send general emails.
- Swagger documentation for all endpoints.
- Python 3.8+
- Django 3.2+
- Django REST framework
- drf-yasg (for Swagger documentation)
-
Clone the repository:
git clone https://github.com/Noah-droid/email-service.git cd mail
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the dependencies:
pip install -r requirements.txt
-
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
-
Apply migrations:
python manage.py makemigrations python manage.py migrate
-
Run the development server:
python manage.py runserver 0.0.0.0:8594
- 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.
- 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.
- 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.
The Swagger UI for API documentation is available at:
- Swagger UI: http://localhost:8594/swagger/
- ReDoc: http://localhost:8594/redoc/