script to send email to every COOP_MANAGERS
This commit is contained in:
25
core/management/commands/sendWelcome.py
Normal file
25
core/management/commands/sendWelcome.py
Normal 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")
|
||||
Reference in New Issue
Block a user