Blog

Sending Email in Django | Django Tutorial for Beginners

Sending Email in Django Website copy
Django

Sending Email in Django | Django Tutorial for Beginners

Sending Email in Django Web Framework

If you are looking that how to send email through the Django application then you are in the right place, we will discuss all Sending emails in the Django web framework. There are different steps you have to follow to work with an email with Django properly. It becomes necessary to send emails to users or groups of users when we want to share something else with users, ebooks, notes, important notes, email verification, etc. If you want to know about sending email in Django, then with care, read this article from start to end.

It is the very best and easy way to communicate with users, clients, customers, etc. There are different ways for communication but email is a simple and secure way. We are learning how you can send email through the Django application. There are different examples when you receive email from the website when you are using in different aspects as for forgetting the password, email verification, account successfully creation etc

What is Django Framework?

Django is the product of Adrian Holovaty and Simon Willison. They are the real developer of Django. It is purely based on the Python programming language which is the most famous general and interpreted programming language. It is the TOP web framework from all other Python-based web frameworks which have standard and quality features that make it unique from others. There are a lot of web applications, websites that are developed by Django. Most famous companies like Disqus, National Geographic, Mozilla, etc.

Why need to send an email?

Email is the best way to communicate with each other that is a simple, easy and secure way. It is the professional way to talk with your customer, share products, share knowledge, tips, etc. So, there are some reasons in the following due to that we used email.

  • Business communication way
  • To market your products
  • To engage users
  • To verify email/email verification
  • Welcome message to new users
  • Share importance resources/links/knowledge etc

Steps in Sending Email in Django?

If you follow these steps which i am going to share with you, you will be able to send email to any email throgh Django applicaiotn.

Step#1

#Here you have to mention basic settings for email sending.
EMAIL_BACKEND = ‘django.core.mail.backends.smtp.EmailBackend’
EMAIL_HOST = ‘smtp.gmail.com’
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = ‘mention your email from which email will send’
EMAIL_HOST_PASSWORD = ‘mention password of your email address, as above you mentioned

Step#2

You have to open views.py file and paste this code, but you have to modify some thing according to your models field, filed name, other settings as you want etc.

from django.conf import settings
from django.core.mail import send_mail
def regestration(request):
    if request.method == “POST”:
        username = request.POST[‘username’] 
        first_name = request.POST[‘first_name’]
        last_name = request.POST[‘last_name’]
        password = request.POST[‘password’]
        email = request.POST[’email’]
        new_user = User.objects.create_user(username = username,first_name = first_name, last_name = last_name,  password = password, email = email)
        login (request, new_user)
        subj = ‘Mention your email subject’
        msg = f’Welcome to {new_user.username} at JafriCode.’
        from = settings.EMAIL_HOST_USER
        recipient_list = [new_user.email, ]
        send_mail( subj, msg, from, recipient_list )
        return redirect (“/user_account”)
    return render (request, ‘user/regestration.html’)

Step#3 (Don’t need if you have already done)

All the settings related to sending email is completed, but you can get an error if your email host is Gmail. Because Google makes your account secure. So to make your email account used for the less secure app then you have to follow some step

Login into your email account, from which you want to send email

Go to this link, ( Less secure app setting) you will be redirected to this page, which is showing that “Allow less secure apps: OFF”.

Jafricode email sending in django

if it is Off you have to turn it into On. Then you can send an email from Django easily.

Now! what you have to do?

As you have understood this article about “Sending Email in Django”, now you must follow instructions as discussed in this article. In case of any issues or problems, don’t worry, you can discuss them with us.

On other hand, If you have any suggestions or knowledge about this article, you can share it with us, we will appreciate you!

If this article is good then share it on FacebookTwitterPinterestInstagram, etc.

Advanced Tutorials for Beginners

Django Model Inheritance | Django Tutorial for Beginners

What is Django Cache | Django Tutorial for Beginners

SEO | Django SEO Optimization Tips 2021 | Django Tutorials

Django Form with Full Explanation | Complete Django Tutorials 

Complete Guide on Prerequisites for Learning Django? | Django Tutorials

Leave your thought here

Your email address will not be published.

Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
  • Attributes
  • Custom attributes
  • Custom fields
Click outside to hide the compare bar
Compare
Wishlist 0
Open wishlist page Continue shopping