From 62d094e60832955351504e2ab506ba16b599c3f7 Mon Sep 17 00:00:00 2001 From: kj1352 Date: Thu, 7 Jul 2022 20:05:15 +0530 Subject: [PATCH] test mail to test send grid --- requirements.txt | 5 +++++ workx_backend/settings/local.py | 3 ++- workx_backend/urls.py | 5 +++-- workx_backend/views.py | 13 +++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 22bacd4..2081d3f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,6 +6,7 @@ coreschema==0.0.4 Django==4.0.6 django-cors-headers==3.13.0 django-filter==22.1 +django-sendgrid-v5==1.2.0 djangorestframework==3.13.1 drf-yasg==1.20.0 drfpasswordless==1.5.8 @@ -17,10 +18,14 @@ Markdown==3.3.7 MarkupSafe==2.1.1 packaging==21.3 pyparsing==3.0.9 +python-http-client==3.3.7 pytz==2022.1 requests==2.28.1 ruamel.yaml==0.17.21 ruamel.yaml.clib==0.2.6 +sendgrid==6.9.7 +sendgrid-django==4.2.0 sqlparse==0.4.2 +starkbank-ecdsa==2.0.3 uritemplate==4.1.1 urllib3==1.26.9 diff --git a/workx_backend/settings/local.py b/workx_backend/settings/local.py index c1063f5..cb513fe 100644 --- a/workx_backend/settings/local.py +++ b/workx_backend/settings/local.py @@ -4,7 +4,8 @@ DEBUG = True ALLOWED_HOSTS = ['localhost'] -EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' +EMAIL_BACKEND = "sendgrid_backend.SendgridBackend" +SENDGRID_API_KEY = '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' # Database # https://docs.djangoproject.com/en/4.0/ref/settings/#databases diff --git a/workx_backend/urls.py b/workx_backend/urls.py index 8d48156..f6a4149 100644 --- a/workx_backend/urls.py +++ b/workx_backend/urls.py @@ -1,7 +1,7 @@ from django.contrib import admin from django.urls import path, include from rest_framework import routers -from workx_backend.views import UserViewSet +from workx_backend.views import UserViewSet, test_mail from rest_framework import permissions from drf_yasg.views import get_schema_view from drf_yasg import openapi @@ -29,5 +29,6 @@ urlpatterns = [ path('admin/', admin.site.urls), path('api/', include(router.urls)), path('', include('drfpasswordless.urls')), - ])) + path('test-mail/', test_mail) + ])), ] diff --git a/workx_backend/views.py b/workx_backend/views.py index 4526540..100d26a 100644 --- a/workx_backend/views.py +++ b/workx_backend/views.py @@ -1,4 +1,6 @@ from django.contrib.auth.models import User +from django.core.mail import send_mail +from django.http import HttpResponse from rest_framework import viewsets from workx_backend.serializers import UserSerializer @@ -6,3 +8,14 @@ from workx_backend.serializers import UserSerializer class UserViewSet(viewsets.ModelViewSet): queryset = User.objects.all() serializer_class = UserSerializer + + +def test_mail(request, *args, **kwargs): + send_mail('This is the title of the email', + 'This is the message you want to send', + 'nikhilkj24@gmail.com', + [ + 'nikhilkj.webtrigon@gmail.com', # add more emails to this list of you want to + ] + ) + return HttpResponse('Done')