LucaGent
LucaGent

Reputation: 41

How to add CC recipients to an e-mail in Plone 4?

I'm quite new to Plone and as you can read in the Title line I'm working with Plone 4.

Despite being new to both plone and Python, I've managed to get a fully working page to send rich text mail messages to user-selected members of my web site. What I've done is basically clone (i.e. copy and rename) the sendto, sendto_form, and sendto_template and editing them in order to get what i needed.

As I've said it works quite fine but I need to add a CC recipient, but the MailHost.send() method does not allow for a CC header (and though the secureSend method allows for it, it is a deprecated method in Plone 4). I've also used a template to let the user add an attachment, the template is available at How to send mail with attachments in Plone using a template approach?.

I know that the python email.Header function does exactly what I need, but when I try to import the library I get an insufficient privileges error (I'm logged in as admin).

I've also tried to work around it by using the following approach:

       templ="""Subject: %(subject)s
From: "%(send_from_name)s" <%(envelope_from)s>
To: %(send_to_address)s
CC: %(send_cc_address)s
Content-Type: text/html; charset=UTF-8
Reply-To: %(send_from_address)s

%(comment)s
--
%(signature)s
"""

       message=templ % variables
       context.MailHost.send(message.encode("utf-8"),encode="quoted-printable")

It works almost fine but can't accept accented characters (which are very common in Italian language).

Any ideas?

Thx in advance,

Luca

Upvotes: 4

Views: 430

Answers (1)

vangheem
vangheem

Reputation: 3293

You're reaching the limits of the secure python scripting environment you can use TTW in plone. The email module is not allowed to be imported in this type of script.

The old secureSend method on the MailHost object used to have an method parameter for cc which seemed to have been removed in the latest version which only has a "send" method and no cc parameter.

This means you'll have to move the code to a product on the file system in a view in order to use the cc part.

Upvotes: 2

Related Questions