python:grok_setup_sendmail
Dies ist eine alte Version des Dokuments!
setup.py:
.. 'zope.sendmail', ..
configure.zcml:
<configure xmlns="http://namespaces.zope.org/zope" xmlns:grok="http://namespaces.zope.org/grok" xmlns:mail="http://namespaces.zope.org/mail" > <include package="grok" /> <includeDependencies package="." /> <grok:grok package="." /> <mail:smtpMailer name="my-app.smtp" hostname="some-smtpserver-fqdn" port="25" /> <mail:queuedDelivery name="mailer" permission="zope.Public" mailer="my-app.smtp" queuePath="mailqueue" /> </configure>
and then my app.py:
import email.MIMEText import email.Header from zope.sendmail.interfaces import IMailDelivery from zope.component import getUtility import grok class Emaildemo(grok.Application, grok.Container): pass class Index(grok.View): pass # see app_templates/index.pt def send_email(sender, recipient, subject, body): msg = email.MIMEText.MIMEText(body.encode('UTF-8'), 'plain', 'UTF-8') msg["From"] = sender msg["To"] = recipient msg["Subject"] = email.Header.Header(subject, 'UTF-8') mailer = getUtility(IMailDelivery, 'mailer') mailer.send(sender, [recipient], msg.as_string()) class SendEmail(grok.EditForm): @grok.action("send email") def send(self,**data): send_email("hans@foobar.de","j.adner at fh-sm.de","test","some body text")
after submit the button in http://localhost:8080/testapp/sendemail I got an email.
And in my app-folder, a new directory appears named mailqueue with Maildir-structure in.
python/grok_setup_sendmail.1345044788.txt.gz · Zuletzt geändert: 2024/08/07 13:35 (Externe Bearbeitung)