In This Modern Era, Email marketing is an important tool to build relationships with customers because it gives freedom to directly communicate with customers.
For successful email marketing, we need to implement some email marketing tools on our website. In this article, I am going to highlight one of an email marketing tool named ‘Mailchimp.’
Mailchimp is a prominent email marketing tool that allows its customers to add email to their subscriber list from websites to use these emails for email campaigns. Mailchimp API provides you to send email to an audience who subscribed to your website. The audiences are also known as Lists.
Preface:
This blog is going to cover how to set up a Mailchimp account and implementation on the server-side. We will cover the steps in the following order:
Setting up Mailchimp account:
Here you need to make a Mailchimp Account. It is free of cost. After that, you will navigate to the Dashboard of Mailchimp.
Create a new audience and generating audience id:
Installing Mailchimp library for Django:
pip install Mailchimp-marketing
Adding required values in settings.py file for Mailchimp:
# Mailchimp credentials
Mailchimp_API_KEY = "Your API keys here"
Mailchimp_DATACENTER = 'us7'
Mailchimp_LIST_ID = "Your list id
Create a view to add email to Mailchimp:
from rest_framework import status
from Mailchimp_marketing import Client
from rest_framework.response import Response
from rest_framework.generics import GenericAPIView
from Mailchimp_marketing.api_client import ApiClientError
from Mailchimp_integration.settings import (
Mailchimp_API_KEY,
Mailchimp_DATA_CENTER,
Mailchimp_LIST_ID,
)
class MailSubscriptionAPIView(GenericAPIView):
def subscribe_email(email):
“””
This function will communicate with Mailchimp api
to create a member in an audience list
“””
Mailchimp = Client()
Mailchimp.set_config({
“api_key”: Mailchimp_API_KEY,
“server”: Mailchimp_DATA_CENTER
})
member_info = {
“email_address”: email,
“status”: “subscribed”,
}
try:
Mailchimp.lists.add_list_member(Mailchimp_LIST_ID, member_info)
except ApiClientError as error:
print(error.text)
def post(self, request, *args, **kwargs):
email = request.data[’email’]
MailSubscriptionAPIView.subscribe_email(email)
return Response({
“status_code”: status.HTTP_200_OK,
“message”: “Mail added to Mailchimp”
})
Create an endpoint for the Class-based view :
from django.urls import path
from .views import MailSubscriptionAPIView
urlpatterns = [
path(‘subscribe_email’, MailSubscriptionAPIView.as_view(), name= ‘subscribe-email’ ),
]
In this way, you can add more emails to your subscriber list and can start an email campaign to boost your Business. Also, you can explore the Mailchimp dashboard to learn more about Mailchimp.
GitHub: https://github.com/nihar9938/Mailchimp-integration-with-drf
Nihar is a full stack developer with around 1 year of experience. He is an expert in building python Integrated web applications, creating REST API’s with well designed, testable and efficient code. He is always eager to learn new programming languages and technologies and looking for new ways to optimize the development process.
Get the latest updates by sharing your email.
Flexible Engagement Model | Secure & Scalable Apps | First Time Right Process
Mindbowser helped us build an awesome iOS app to bring balance to people’s lives.
We had very close go live timeline and MindBowser team got us live a month before.
They were a very responsive team! Extremely easy to communicate and work with!
We’ve had very little-to-no hiccups at all—it’s been a really pleasurable experience.
Mindbowser is one of the reasons that our app is successful. These guys have been a great team.
Mindbowser was very helpful with explaining the development process and started quickly on the project.
The greatest benefit we got from Mindbowser is the expertise. Their team has developed apps in all different industries with all types of social proofs.
Mindbowser is professional, efficient and thorough.
Very committed, they create beautiful apps and are very benevolent. They have brilliant Ideas.
MindBowser was great; they listened to us a lot and helped us hone in on the actual idea of the app.” “They had put together fantastic wireframes for us.
They're very tech-savvy, yet humble.
Ayush was responsive and paired me with the best team member possible, to complete my complex vision and project. Could not be happier.
As a founder of a budding start-up, it has been a great experience working with Mindbower Inc under Ayush's leadership for our online digital platform design and development activity.
The team from Mindbowser stayed on task, asked the right questions, and completed the required tasks in a timely fashion! Strong work team!
They are focused, patient and; they are innovative. Please give them a shot if you are looking for someone to partner with, you can go along with Mindbowser.
We are a small non-profit on a budget and they were able to deliver their work at our prescribed budgets. Their team always met their objectives and I'm very happy with the end result. Thank you, Mindbowser team!!