[Zope] Iterating inside Sendmail
Dylan Reinhardt
zope@dylanreinhardt.com
Thu, 21 Nov 2002 14:19:59 -0800
This isn't a DTML problem, per se. You can't send e-mail that isn't
properly formatted... that's your core problem.
Unless the variable you render in the BCC field contains a value that
conforms with RFC822, you won't get the results you're expecting.
Multi-line DTML statements insert line breaks into your output stream...
that's not a problem when they're forming HTML, but it will mess up e-mail
headers. And when you're sending to multiple recipients (on any header),
bear in mind that the correct format is comma delimited, not space delimited.
Try something like:
<dtml-call "REQUEST.set(my_names, [])">
<dtml-in "something_that_produces_addresses()" prefix=recipient>
<dtml-call "my_names.append(recipient_item)">
</dtml-in>
and then in <dtml-sendmail ...>, put:
Bcc: <dtml-var "','.join(my_names)">
HTH,
Dylan
At 01:42 PM 11/21/2002, you wrote:
>Thanks Tino,
>
>I guess this is where dtml just doesn't cut it. i'm real new to Python,
>(just learning it), so I'll try working on this for a while and see if it
>does it or not. I am just confused as to why dtml-in does not work inside of
>sendmail. I also tried, as Mike suggested, creating another method and
>moving the [with / in] statement to it and then calling it as
>Bcc: <dtml-var listNames> and that didn't work either. When I 'viewed' it,
>it appeared to work fine, ie: email@address1.com email@address2.com
>email@address.com etc. but not inside of sendmail.
>
>Michael
>
>
>On Thursday 21 November 2002 02:10 pm, Tino Wildenhain wrote:
> > Hi Michael,
> >
> > just drop DTML for this too and use
> > Mailhost.send() instead. If you have a recent
> > Zope, it strips BCC automatically and you only have
> > to provide it with mailtxt, which is mailheader + 1 free line +
> > mailbody.
> > Minimal mailheader is
> > To: Person <person@target.com>
> > From: Person <person@source.com>
> > Subject: what to say...
> >
> > The simplest way to do this in a loop is to use a Python long string:
> >
> > msg="""To: %(to)s
> > From: %(from)s
> > Subject: Your subject
> >
> > Hi there,
> > foobar...
> > """.replace('\n','\r\n')
> >
> > The replace stepp changes the line endings from single newline (Unix,
> > python) to
> > carriage-return + newline, which is for rfc822 complience.
> >
> > all_addresses=[{'to':'Person1 <person1@person1.com>,'from':'Me
> > <myself@me.com>'},
> > {'to':'Person2 <person2@person2.com>,'from':'Me
> > <myself@me.com>'},
> > {'to':'Person1 <person3@person3.com>,'from':'Me
> > <myself@me.com>'}]
> >
> > for target in all_addresses:
> > Mailhost.send(msg % target)
> >
> > This is untested, but schould give you a starting point.
> >
> > Does this help?
> >
> > Regards
> > Tino Wildenhain
> >
> > --On Donnerstag, 21. November 2002 13:38 -0700 Michael
> >
> > <michael@nichestaffing.com> wrote:
> > > I have put up a small job site for Linux jobs here in N. Colorado. I
> > > want to offer the option of entering an email address and have job
> > > postings emailed directly to subscribers as they are posted. I tried
> > > the example below, but there seems to be a problem iterating inside
> > > sendmail.
> > >
> > > For the time being, I just created a method and manually entered all the
> > > email addresses in it, ie: Bcc: <dtml-var listNames>, but I would like to
> > > automate it if possible. Does anyone have any idea on how to approach
> > > this?
> > >
> > > Michael
> > >
> > >
> > > <dtml-with entries>
> > >
> > > <dtml-call "REQUEST.set('post_name', post_name)">
> > > <dtml-call "REQUEST.set('post_type', post_type)">
> > > <dtml-call "REQUEST.set('post_email', post_email)">
> > > <dtml-call "REQUEST.set('description', description)">
> > > <dtml-call "REQUEST.set('company_name', company_name)">
> > > <dtml-call "REQUEST.set('company_domain', company_domain)">
> > > <dtml-call "REQUEST.set('position_title', position_title)">
> > > <dtml-call "REQUEST.set('org_city', org_city)">
> > > <dtml-call "REQUEST.set('title', post_name+' - '+post_type+' -
> > > '+position_title)">
> > >
> > > <dtml-with "manage_addProduct['NCLJobs']">
> > > <dtml-call "ncl_jobs_entry_add(_.None, _, NoRedir=1)">
> > > </dtml-with>
> > > </dtml-with>
> > >
> > > <dtml-sendmail mailhost="MailHost">
> > > To: linux@jymis.com
> > > From: linux-jobs@jymis.com
> > > Bcc:
> > > <dtml-with listEntries>
> > > <dtml-in Catalog>
> > > <dtml-var email_address>
> > > </dtml-in>
> > > </dtml-with>
> > > Subject: Northern Colorado Linux Jobs Autoresponder
> > > <dtml-mime type=text/plain encode=7bit>
> > > POSTING TYPE: <dtml-var post_type>
> > > COMPANY NAME: <dtml-var company_name>
> > > COMPANY DOMAIN: <dtml-var company_domain>
> > > CONTACT EMAIL: <dtml-var post_email>
> > > POSITION TITLE: <dtml-var position_title>
> > > LOCATION / CITY: <dtml-var org_city>
> > >
> > > DESCRIPTION: <dtml-var description>
> > > </dtml-mime>
> > > </dtml-sendmail>
> > >
>
>_______________________________________________
>Zope maillist - Zope@zope.org
>http://lists.zope.org/mailman/listinfo/zope
>** No cross posts or HTML encoding! **
>(Related lists -
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )