[Django]-Django Send emails to all users in the database table

6👍

battery’s answer is ok, but i would do this way:

recievers = []
for user in Users.objects.all():
    recievers.append(user.email)

send_mail(subject, message, from_email, recievers)

this way, you will open only once connection to mail server rather than opening for each email.

0👍

Sending email is very simple.
For your Users model this would be:

for user in Users.objects.all():
    send_mail(subject, message, from_email,
        user.Email)

Checkout Django’s Documentation on send emails for more details.

Would be useful if you mention what problem you are facing if you’ve tried this.

Also note, IntegerField does not have a max_length argument.

-1👍

for user in Users.objects.all():
send_mail(subject, message, from_email,
user.Email)

This is the best solutions and it works well

Leave a comment