EMAIL_BACKEND =‘django.core.mail.backends.smtp.EmailBackend
EMAIL_HOST = ‘smtp.gmail.com’
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = ‘your_account@gmail.com’
EMAIL_HOST_PASSWORD = ‘your account’s password’
To configure you Django Project, add the following parameters to your settings.py
EMAIL_HOST = 'smtp.mailgun.org'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'postmaster@mg.bottlenose.co'
EMAIL_HOST_PASSWORD = 'mys3cr3tp4ssw0rd'
EMAIL_USE_TLS = True
Here is a very simple snippet to send an email:
from django.core.mail import send_mail
send_mail('subject', 'body of the message', 'noreply@bottlenose.co', ['vitor@freitas.com'])
from django.core.mail import send_mail
class UserList(generics.ListCreateAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
def perform_create(self, serializer):
created_object = serializer.save()
send_mail('Subject here','Here is the message.','from@example.com',
[created_object.email], fail_silently=False,)