My Django application has 10,000 users, all with emails. I would like to send an email message to all of them say once a month. This message could have some pdf attachments.
What I have tried is using an EmailMessage object to send an email to all of them. I add all users' email addresses to the bcc component of this EmailMessage before sending.
recList = []
for recipient in rec:
reci = str.strip(str(recipient))
recList.append(reci)
message = (form.cleaned_data['subject'], form.cleaned_data['message'], '[email protected]', recList)
mail = EmailMessage(form.cleaned_data['subject'], form.cleaned_data['message'], '[email protected]', ['[email protected]'], recList)
num_attachments = 0
if form.cleaned_data['attachment'] != None:
email_attachment = EmailAttachment(
document_name = form.cleaned_data['attachment'].name,
email_message = email,
document = form.cleaned_data['attachment'],
)
email_attachment.save()
mail.attach_file(settings.MEDIA_ROOT + "/" + email_attachment.document.name)
mail.send(fail_silently=False)
However, when I send the email, Django complains that "The connection was reset" and does not send. I am assuming that the server connection was closed.
What's an efficient way to send a mass email blast in Django? Would send_mass_mail()
be more effective?