Hi Peter,

On 19/12/2007, at 8:18 AM, Peter Baumgartner wrote:

>
> I've built a newsletter app that currently cycles through 500+ emails
> and I'd like to have it scale to handle more.
>
> Currently I just have code like this in my view:
>
> for recipient in email_list:
>    msg = EmailMultiAlternatives(email.subject, email.message_text,
> email.sender, [recipient])
>    msg.attach_alternative(email.message_html, 'text/html')
>    msg.send()
>
> it seems to hang up the browser for quite a while with even just a few
> emails. What is the best way to do this and give the user confirmation
> that the email has been sent to everyone?
>
> Should I fork off a new process? If so, how can I be sure it finishes
> successfully?

I wrote a newsletter app that does this (and more) and is about to  
become public, just as soon as I clean it up and make sure it works  
outside the site it was developed for... might be too late for you  
though.

It uses the method that Rajesh describes in his reply - it create a  
Delivery record for each recipient, with a foreignkey pointing to the  
newsletter to be mailed. An hourly cron job pulls a certain amount of  
Delivery entries (can't just send all of them at once because some  
hosting providers think you're a spammer if you do that), sends them  
and marks them as "sent". The newsletter object itself gets marked as  
"sent" as soon as the Delivery objects are created, so you won't send  
it a 2nd by accident while its delivery is pending.

As for knowing that the delivery has finished, adding that should be  
easy - just count unsent delivery objects. I use a "send" button in  
the admin newsletter list view (changing to "sent" after the send),  
the delivery count could easily be displayed next to it.

Let me know if you want a look at the mailing code before the whole  
app is available.

Itai

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to