2

I have to send bulk email in django, the email template will be will be customized and the some data in the template will be coming from db. i twas using django notification but it can only send email to the registered users. I have to send emails to the non-registered users. there will be five email template the user can select any one and the email has to be sent.

For ex. An invitation to the event to the group of non-registered users. user will enter email ids, and will do a bulk send. which django package can i use to achieve the same.

Nilesh
  • 167
  • 1
  • 4
  • 17

1 Answers1

11

You can use django's default sending multiple email system. From here: https://docs.djangoproject.com/en/dev/topics/email/#sending-multiple-emails

You can try like this:

from django.core import mail
connection = mail.get_connection()

connection.open()
reciever_list= ['aa@bb.cc', 'dd@ee.ff']  #extend this list according to your requirement
email1 = mail.EmailMessage('Hello', 'Body goes here', 'from@example.com',
                          reciever_list, connection=connection)
email1.send()
connection.close()

For bulk email reference, you can check this so answer: How does one send an email to 10,000 users in Django?

Edit

From this stackoverflow answer, you can send emails with template. If you use django 1.7, html_message can be added as perameter of send_mail(). Details here.

By the way, for mass email handling, django has send_mass_mail() method.

ruddra
  • 50,746
  • 7
  • 78
  • 101
  • Thanks @ruddra, this helps but i have a specific email template for invitation(with proper spacing and indentation). is there anyway here so that it takes the appropriate template and send accordingly. – Nilesh Jun 29 '14 at 15:25
  • Yes there is. I have added a reference in my answer on howto. – ruddra Jun 29 '14 at 16:57
  • Would it work, if from@example.com or simply example.com is already set up with a email provider? like Zoho. – Sidhin S Thomas Jun 17 '17 at 01:08
  • Please note connection need to be closed using `connection.close()` Source: https://docs.djangoproject.com/en/3.0/topics/email/#sending-multiple-emails – JD Solanki Jul 14 '20 at 16:07
  • 1
    Link has dissappeared (version of Django 1.6). New link is here: https://docs.djangoproject.com/en/3.2/topics/email/#send-mass-mail send_mass_mail() vs. send_mail()¶ The main difference between send_mass_mail() and send_mail() is that send_mail() opens a connection to the mail server each time it’s executed, while send_mass_mail() uses a single connection for all of its messages. This makes send_mass_mail() slightly more efficient. – Hvitis Jun 27 '22 at 19:36