(メール送信)

はじめに

This document tells how to send email from Plone.

Email can be sent

  • Manually calling MailHost
  • Content rule based (content rules have default email out action) which can be activated e.g. workflow transition
  • Triggering email based password reset

Manually calling MailHost

After your mail_text is prepared, sending it is a simple as:

try:
 host = getToolByName(self, 'MailHost')
 return host.send(mail_text)
except SMTPRecipientsRefused:
 # Don't disclose email address on failure
 raise SMTPRecipientsRefused('Recipient address rejected by server')

Preparing mail text: ‘mail_text’ can be generated by calling a page template (.pt) with keyword arguments. The values are accessed in the template as ‘option/keyword’ For example, a sample template:

<tal:root define="lt string:&lt;;gt string:&gt;;
                  dummy python:request.RESPONSE.setHeader('Content-Type', 'text/plain;; charset=%s' % options['charset']);
                  member python:options['member'];"
>From: "<span tal:replace="python:here.email_from_name" />" <span tal:replace="structure lt"/><span tal:replace="python:here.email_from_address" /><span tal:replace="structure gt"/>
To: <span tal:replace="python:member.getProperty('email')" />
Subject: <span i18n:domain="yourproduct" i18n:translate="yoursubjectline" tal:omit-tag="">Subject Line</span>
Content-Type: text/plain; charset=<span tal:replace="python:options['charset']" />
Dear  <span tal:replace="member/getFullname" /> :
You can now log in as <span tal:replace="member/getId" /> at <span tal:replace="python:options['portal_url']" />
Cheers!
The website team
</tal:root>

can be called with a member object and the portal_url:

mail_template = portal.mail_template_id
mail_text = mail_template(member=member,
                          portal_url=portal.absolute_url(),
                          charset=email_charset,
                          request=REQUEST)

For more complete examples (with i18n support, etc) see the password reset modules. (particularly Products.remember.tools.registration)

目次

前のトピックへ

(Zope の日時型 (DateTime))

次のトピックへ

(アノテーション)

このページ