Dhesend

Python

Django

Learn how to send emails in Django using Dhesend Python SDK.

Prerequisites
To get the most out of this guide, you’ll need to:
1. Install Dhesend SDK
Install the Dhesend Python SDK using pip to get started.
1pip install dhesend
2. Create email sending view

Add a view in views.py to handle email sending and link it in urls.py.

1from django.http import JsonResponse
2from dhesend import Dhesend, SendEmailPayload
3
4def send_email(request):
5    dhesend = Dhesend("your-apikey")
6    
7    params: SendEmailPayload = {
8        "from": "Dhesend <example@domain.com>",
9        "to": ["example@dhesend.com"],
10        "subject": "Welcome to Dhesend",
11        "htmlBody": "<strong>Have a nice day!</strong>",
12    }
13
14    try:
15        response = dhesend.Email.send(params)
16        return JsonResponse(response)
17    except Exception as e:
18        return JsonResponse({
19            "error": "An error occurred while sending the email."
20        }, status=500)

Dhesend @ 2024 - Made with ❤ by  DHEM