script to send email to every COOP_MANAGERS

This commit is contained in:
Diego Calvo
2021-03-31 14:55:21 +02:00
parent 7399b6a480
commit 50ada7c6b6
4 changed files with 710 additions and 1 deletions

View File

@@ -0,0 +1,25 @@
from django.core.management.base import BaseCommand
from django.core.mail import EmailMessage
from django.template.loader import render_to_string
from core.models import CustomUser
class Command(BaseCommand):
def handle(self, *args, **kwargs):
print("Send welcome email to coop managers\n")
managers = CustomUser.objects.filter(role='COOP_MANAGER')
for manager in managers:
link = "https://latienda.coop/login"
company_message = render_to_string('welcome_coop.html', {
'manager': manager,
'link': link
})
# send email to company
subject = "Bienvenid@ a LaTienda.COOP"
email = EmailMessage(subject, company_message, to=[manager.email])
email.content_subtype = "html"
email.send()
print(f"Messages sent to {len(managers)} coop managers")