Yeah I've used the template engine for this before and it has worked well.
No complaints and it's relatively simple:

            from django.core.mail import send_mail
            from django.template import loader, Context

            t = loader.get_template('my/template.txt')

            send_mail('subject', t.render(Context(template_variables_dict)),
'f...@domain.com', recipient_list)

Just remember you can exclude a lot of that to outside the loop (eg: you
don't want to reload the template for every user and you might be able to
generate some of the template dictionary beforehand too)

And recipient_list will probably want to be just one person at a time -- but
it still has to be in list format. I'm saying all this, not because I think
you don't know this, but people that read this in the future (haha - users
searching before they ask!) might find it useful.


On Thu, Apr 2, 2009 at 2:58 AM, Joey Gartin <joeygar...@gmail.com> wrote:

> Newbie question:
>
> In a view I am sending out a few emails to users.  The email format is
> identical for each user, with the users information being dynamic.
>
> My question is regarding forming a long email and using it as the body over
> and over (in a loop for each user).  What is the best way to do this?  If
> the email were just one or two lines then I would build a string prior to
> the send_email call, but this is about 18 lines with 11 variables.  Is there
> a standard way to do this?  Using a separate file as a template and in my
> loop plugging the user information into the template and then making the
> send_email body the template seems like the ideal thing, but I am not sure
> if that is the proper Django way???
>
> Thank you!
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to