send mail - sendgrid - django

 SourceURL:file:///home/wadmin/My Files/send mail sendgrid.docx


support docs: https://github.com/sklarsa/django-sendgrid-v5

 

 

views.py

from django.shortcuts import render

 

from rest_framework.views import APIView

from rest_framework.response import Response

from rest_framework import status

 

from .serializers import *

from django.core.mail import send_mail

 

class MailSendList(APIView):

    def post(self, request, format=None):

        data = request.data

        subject = data.get("subject")

        message = data.get("mailbody")

        mail_from = data.get("mailfrom")

        mail_to = data.get("mailto")

 

        try:

            send_mail(

            subject,

            message,

            mail_from,

            [mail_to],

            fail_silently=False,

            )

            return Response({"mail send!"})

        except Exception as e:

            print(e)

            return Response({"message":"error occured!"})

 

settings.py

# custom settings

EMAIL_BACKEND = "sendgrid_backend.SendgridBackend"

SENDGRID_API_KEY = os.environ.get("SENDGRID_API_KEY")

SENDGRID_SANDBOX_MODE_IN_DEBUG = False

 

 

Popular posts from this blog

MCSL 216 MCA NEW Practical ~ common questions suggestions

dev chaeatsheet

STRAPI