This task would be better left to a background batch processor such as Celery, which integrates nicely via the Django-celery package. Submitting the form would place a job into the Celery queue, and within that job you can pull 100 (or however many you need, see https://docs.djangoproject.com/en/1.6/topics/db/queries/#limiting-querysets) addresses at a time in a loop and send them out, waiting for each chunk to complete before sending the next set.
This also keeps your users from waiting for the email sending task to complete before returning a response, otherwise the page will 'hang' after submission while all of the emails are being sent, which may or may not be acceptable for your user base, but I would caution against it given other constraints such as browser and connection timeouts, not to mention holding up resources and worker threads on your web server from being available to other users. -James On Friday, May 2, 2014, MikeKJ <mike.jo...@paston.co.uk> wrote: > def send( self ): > c = Context({ "content": self.introductory_text, "user":None, > "request":None, "updates": [] })#Section.updates.all()[:20] }) > t = loader.get_template('emailer/html/updates.html') > subject = self.subject > recipients = [] > if self.to_all_principal_contacts: > self.add_principal_contacts() > if self.to_all_subscribers: > self.add_subscribers() > for i in self.recipients.all(): > recipients.append( i.email ) > self.save() > html = t.render(c) > for i in recipients: > send_html_email( subject, html, "emailataddress.com", i, > image_root=settings.PROJECT_DIR ) > from datetime import datetime > self.sent_on = datetime.now() > self.sent = True > self.save() > > What I want to do is break recipients[] into chunks of say 100 and then > send_html_email on each email address within each chunk for all chunks BUT > I want to preserve the self.sent = True self.save() to be done after all > chunks have been sent. > I think it may also need some method of timebreak between each chunk being > processed. > This is come about because the server/host seems to have a problem with > sending 1500 emails in one go. The above sends to small numbers but not > all in one go. > > Thanks for helping > > > > > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to > django-users+unsubscr...@googlegroups.com<javascript:_e(%7B%7D,'cvml','django-users%2bunsubscr...@googlegroups.com');> > . > To post to this group, send email to > django-users@googlegroups.com<javascript:_e(%7B%7D,'cvml','django-users@googlegroups.com');> > . > Visit this group at http://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/fc804755-1bc1-43f0-a15f-a98984be04fa%40googlegroups.com<https://groups.google.com/d/msgid/django-users/fc804755-1bc1-43f0-a15f-a98984be04fa%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciWrzEeutjTGpJ1cB21yxMx3v08tHSrLW8kjuJjXCwxBdg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.