[Grok-dev] sending emails by grok

Jens Adner j.adner at fh-sm.de
Thu Jul 23 07:58:22 EDT 2009


Mmmmh, I found a configure.zcml in my app-folder where the app.py lives
just after create a new grokproject.

Best regards
Jens

Sebastian Ware schrieb:
> Is this the same as site.zcml in a zopectl configuration? I can't find a
> configure.zcml except in parts/i18n.
> 
> Mvh Sebastian
> 
> 15 jul 2009 kl. 15.35 skrev Jens Adner:
> 
>> huuuh, it works. great!
>>
>> I put the utility stuff in 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="smtp.fh-schmalkalden.de"
>>      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 at 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.
>>
>> looks good so far.
>>
>> Best regards
>>
>> Sebastian Ware schrieb:
>>> Is it correct that all I need to send emails using zope.sendmail through
>>> a local SMTP-server is to define two global utilities like this:
>>>
>>> from zope.sendmail.interfaces import IMailDelivery, ISMTPMailer
>>>
>>> from zope.sendmail.delivery import QueuedMailDelivery
>>> class MyMailer(grok.GlobalUtility, QueuedMailDelivery):
>>>    grok.implements(IMailDelivery)
>>>    grok.name('my-app.mailer')
>>>
>>>    def __init__(self):
>>>        QueuedMailDelivery.__init__(queuePath='var/mailqueue')
>>>
>>> from zope.sendmail.mailer import SMTPMailer
>>> class MyMailer(grok.GlobalUtility, SMTPMailer):
>>>    grok.implements(ISMTPMailer)
>>>    grok.name('my-app.smtp')
>>>
>>> Mvh Sebastian
>>>
>>> 15 jul 2009 kl. 13.34 skrev Souheil CHELFOUH:
>>>
>>>> zope.sendmail is a very good choice.
>>>> It's very effective, fast and reliable, from my experience.
>>>>
>>>> 2009/7/14 Jens Adner <j.adner at fh-sm.de>
>>>> Hello,
>>>>
>>>> I would like to use a view in grok to allow our user to create a
>>>> support
>>>> request.
>>>>
>>>> After submitting the form I would like generate an email.
>>>>
>>>> I read about zope.sendmail. Is this the latest package I should use to
>>>> send an email or are there other choices (maybe better)?
>>>>
>>>> Greetings
>>>> Jens
>>>> -- 
>>>> ++++++++ Jens Adner IuK-Zentrum Fachhochschule Schmalkalden +++++++++
>>>> ++++++++ Fon: +49 3683688 9201  Fax: +49 3683688 989201     +++++++++
>>>> _______________________________________________
>>>> Grok-dev mailing list
>>>> Grok-dev at zope.org
>>>> http://mail.zope.org/mailman/listinfo/grok-dev
>>>>
>>>> _______________________________________________
>>>> Grok-dev mailing list
>>>> Grok-dev at zope.org
>>>> http://mail.zope.org/mailman/listinfo/grok-dev
>>>
>>
>> -- 
>> ++++++++ Jens Adner IuK-Zentrum Fachhochschule Schmalkalden +++++++++
>> ++++++++ Fon: +49 3683688 9201  Fax: +49 3683688 989201     +++++++++
> 

-- 
++++++++ Jens Adner IuK-Zentrum Fachhochschule Schmalkalden +++++++++
++++++++ Fon: +49 3683688 9201  Fax: +49 3683688 989201     +++++++++


More information about the Grok-dev mailing list