even better!
On June 22, 2002 10:02 am, Mike Orr wrote:
> On Sat, Jun 22, 2002 at 11:38:35AM -0500, Tracy Ruggles wrote:
> > What is the best way to loop over a set of data and only use one
> > template?
> >
> > For speediness, I don't want to re-instantiate a new template every
> > time I want to send out an email (I'm sending to nearly 4,000 and the
> > list is growing every week).
> > Here's what I do now:
> >
> > The line where I delete _searchList[-1], I know, is really bad coding=
=2E
> > But, I couldn't find any other way to reset the search list so I coul=
d
> > re-use it to send the email. Is there a way to set the search list
> > anew every time I want to use it?
>
> You don't need to replace the search *list*, you just need to update
> those certain variables (or in this case, one variable). You can
> either save a reference to the dictionary in an ordinary Python
> variable and modify the dictionary in place between e-mails, or skip th=
e
> dictionary entirely and set the variables directly in the template
> object.
>
> You can gain startup speed improvement by using a precompiled
> template.
> =09cheetah compile -p massMailer.txt >massMailer.py
>
>
> -- begin sample.py --
>
> from massMailer import massMailer
> import smtplib
>
> mailer =3D smtplib.SMTP('mydomain.com')
> emailTemplate =3D massMailer()
> emailAddresses =3D [...] # long list of emails
>
> for email in emailAddresses:
> emailTemplate.EmailAddress =3D email
> mailer.sendmail ('me@...', email, str(emailTemplate) )
>
> -- end sample.py
|