Skip to content

Instantly share code, notes, and snippets.

@lopinho
Last active January 2, 2020 14:47
Show Gist options
  • Save lopinho/d5bbd44b51638eccac349998d6cc5dc2 to your computer and use it in GitHub Desktop.
Save lopinho/d5bbd44b51638eccac349998d6cc5dc2 to your computer and use it in GitHub Desktop.
from usuarios.models import *
from django.conf import settings
from django.core.mail import EmailMessage
estado = 'BA'
destinatarios = ['tatyane@grupobaraka.com.br', 'glaucia@tree.sh']
emails = User.objects.filter(userprofile__localidade__estado__sigla=estado, userprofile__ativo_para_o_site=True).values_list('email', flat=True)
message = EmailMessage('Emails do estado %s' % estado, 'em anexo', settings.EMAIL_HOST_USER, destinatarios)
message.attach('emails_%s.txt' % estado, "\n".join(emails), 'text/plain')
message.send()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment