There are 10,000 users in my Django app, all with emails. I would like to send an email to everyone that they say once a month. This post may contain some pdf attachments.
I tried using the EmailMessage object to send email to all of them. Before sending, I add the email addresses of all users to a composite copy of this EmailMessage.
recList = [] for recipient in rec: reci = str.strip(str(recipient)) recList.append(reci) message = (form.cleaned_data['subject'], form.cleaned_data['message'], ' emailAdmin@yahoo.com ', recList) mail = EmailMessage(form.cleaned_data['subject'], form.cleaned_data['message'], ' email_manager@mysite.org ', [' email_list@mysite.org '], 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 an email, Django complains that the “connection was reset” and does not send. I assume that the connection to the server was closed.
What is an effective way to send bulk email in Django? Will send_mass_mail() more efficient?
source share