3

Is there any way to send a verification email. when an user registers through drf (Django Rest framework). I have this code in my User model:

from django.core.mail import send_mail
from config import settings

def email_user(self, subject, message, from_email=settings.DEFAULT_FROM_EMAIL, **kwargs):        
    send_mail(subject, message, from_email, [self.email], fail_silently=False, **kwargs)

and in my settings.py:

EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_PASSWORD = '`132312123'
EMAIL_HOST_USER = '[email protected]'
EMAIL_PORT = 587
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

But email not being sent, also I want to verification email service, so user will be activated when they click on the link. How to accomplish these?

1 Answer 1

7

If you look here:

Console backend

Instead of sending out real emails the console backend just writes the emails that would be sent to the standard output. By default, the console backend writes to stdout. You can use a different stream-like object by providing the stream keyword argument when constructing the connection.

Also:

This backend is not intended for use in production – it is provided as a convenience that can be used during development.

Try this one instead:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
Sign up to request clarification or add additional context in comments.

1 Comment

Good answer! I also suggest looking at email backends that send asynchronously, so that your users don't have to wait for the email to be actually sent (which is a slow process). I have been using github.com/pinax/django-mailer flawlessly. It uses database and it's dead simple to setup.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.