如何在 Plone 4 中将抄送收件人添加到电子邮件中?
我对 Plone 还很陌生,正如你可以在标题行中读到的那样,我正在使用 Plone 4。
尽管对 plone 和 Python 都很陌生,但我已经设法获得一个完全工作的页面来发送富文本邮件消息到我的网站的用户选择的成员。 我所做的基本上是克隆(即复制和重命名)sendto、sendto_form 和 sendto_template 并编辑它们以获得我需要的内容。
正如我所说,它工作得很好,但我需要添加一个抄送收件人,但 MailHost.send() 方法不允许使用抄送标头(尽管 secureSend 方法允许,但它是 Plone 中已弃用的方法4). 我还使用了一个模板来让用户添加附件,该模板位于 如何使用模板方法在 Plone 中发送带附件的邮件?。
我知道 python email.Header 函数完全符合我的需要,但是当我尝试导入库时,我收到权限不足的错误(我以管理员身份登录)。
我还尝试使用以下方法来解决它:
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")
它几乎可以正常工作,但不能接受重音字符(这在意大利语中很常见)。
有什么想法吗?
提前谢谢,
卢卡
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已经达到了可以在 plone 中使用 TTW 的安全 python 脚本环境的限制。此类脚本中不允许导入电子邮件模块。
MailHost 对象上旧的 secureSend 方法曾经有一个用于抄送的方法参数,该参数似乎已在最新版本中删除,该版本只有“发送”方法而没有抄送参数。
这意味着您必须将代码移动到视图中文件系统上的产品才能使用 cc 部分。
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.