Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

sending mail with Plomino form

Developers
Giovanni
2011-11-10
2013-04-25
1 2 > >> (Page 1 of 2)
  • Giovanni
    Giovanni
    2011-11-10

    Hi!
    I created a Plomino (1.9) form for sending mail with the following fields:
    - To (field type: name)
    - Topic
    - Body (the text message)
    - attachment

    I tried to write the following python code on a action or on the onsave document:

    message = plominoContext.Body
    mTo = plominoContext.To
    mFrom = context.portal_properties.site_properties.email_from_address
    mSubject = plominoContext.Topic
    context.MailHost.send(message, mto=mTo, mfrom=mFrom, subject=mSubject)

    but I have the following error:
    TypeError: expected read buffer, Acquisition.ImplicitAcquisitionWrapper found

    Any hints?

    Giovanni

     
  • Giovanni
    Giovanni
    2011-11-10

    Errata corrige: Plomino versione is 1.11.

     
  • Eric Brehault
    Eric Brehault
    2011-11-10

    hello,

    Plomino provides a sendMail function which calls MailHost
    (you see this function code here: https://github.com/plomino/Plomino/blob/github-main/Products/CMFPlomino/PlominoUtils.py#L71 )

    So your code would be:
    db = context.getParentDatabase()
    message = plominoContext.getItem('Body')
    mTo = plominoContext.getItem('To')
    mFrom = db.portal_properties.site_properties.email_from_address
    mSubject = plominoContext.getItem('Topic')
    sendMail(db, mTo, mSubject, sender=mFrom)

    Note: use context.getItem(itemname) to prevent attribute errors

    eric

     
  • Giovanni
    Giovanni
    2011-11-10

    Ok.
    I have the folowing error:
    AttributeError: getItem

    Do you think I have to insert the code on save?

     
  • Giovanni
    Giovanni
    2011-11-10

    I put on onsave event. Moreover the parameter "message" missed.
    So:
    db = context.getParentDatabase()
    message = plominoContext.getItem('Body')
    mTo = plominoContext.getItem('To')
    mFrom = db.portal_properties.site_properties.email_from_address
    mSubject = plominoContext.getItem('Topic')
    sendMail(db, message mTo, mSubject, sender=mFrom)

    I have no error but no mail has arrived.

     
  • Giovanni
    Giovanni
    2011-11-10

    db = context.getParentDatabase()
    message = plominoContext.getItem('Body')
    mTo = plominoContext.getItem('To')
    mFrom = db.portal_properties.site_properties.email_from_address
    mSubject = plominoContext.getItem('Topic')
    sendMail(db, message, mTo, mSubject, sender=mFrom)

     
  • Jean Jordaan
    Jean Jordaan
    2011-11-10

    The `getItem` method is only available on Plomino documents.
    Try `plominoDocument.getItem(…)` instead of `plominoContext.getItem(…)`.
    Also, during document creation you're operating on the form, not yet on a document.
    Call `plominoDocument.isDocument()` to make sure you're on a document.

     
  • Giovanni
    Giovanni
    2011-11-10

    No error but no mail….
    I'm working on onsave event…

     
  • Giovanni
    Giovanni
    2011-11-10

    This is the code:

    db = context.getParentDatabase()
    message = plominoDocument.getItem('Body')
    mTo = plominoDocument.getItem('To')
    mFrom = db.portal_properties.site_properties.email_from_address
    mSubject = plominoDocument.getItem('Topic')
    sendMail(db, mTo, mSubject, message, mFrom).

    Where am I wrong?

     
  • Eric Brehault
    Eric Brehault
    2011-11-10

    Hello,

    the code is correct
    is your Plone configured to send mail ?

     
  • Giovanni
    Giovanni
    2011-11-10

    yes of course.
    I tried to send a page and the email was sent correctly…

     
  • Eric Brehault
    Eric Brehault
    2011-11-10

    ok good

    are you on Plone 3 or Plone 4 (sendMail still uses secureSend with Plone 3, it can be the origin) ?

    eric

     
  • Giovanni
    Giovanni
    2011-11-10

    Plone 4.0.7…

     
  • Eric Brehault
    Eric Brehault
    2011-11-10

    could you connect on the #plomino channel on IRC (freenode), it will be easier to analyse your problem ?

     
  • Giovanni
    Giovanni
    2011-11-10

    yes

     
  • Giovanni
    Giovanni
    2011-11-10

    I'm not able to connect on IRC because of company proxy settings….
    I'm sorry….

     
  • Giovanni
    Giovanni
    2011-11-10

    Eric,
    you can check my Plomino application at
    http://www.plomino.com/Members/giovanni/e-mail

    Hope to receive good news from you.
    Bye

     
  • Eric Brehault
    Eric Brehault
    2011-11-10

    Hello,

    I found the problem: your To field is a name field, so it stores a Plone member id.
    But what we actually need here is the email, not the member id.
    So here is the fix:
    To = plominoDocument.getItem('To')
    mTo = userInfo(db, To).getProperty('email')

    Eric

     
  • Giovanni
    Giovanni
    2011-11-11

    Now it works!
    Thanks a lot.
    Last question: what about the attachment?
    It would be useful to send it within the mail.

     
  • Jean Jordaan
    Jean Jordaan
    2011-11-11

    Plomino's helper method doesn't do attachments.
    For that you'll have to build a multipart Message instance (see http://docs.python.org/library/email.message.html ) and pass it to the MailHost of your Plone. This won't work through the web.

     
  • Giovanni
    Giovanni
    2011-11-11

    Ok. Thank you for all.
    Bye Eric

     
  • Giovanni
    Giovanni
    2011-11-11

    Another problem:
    Selecting more than one recipient, e-mail is sent only to the first one…

    Why?

     
  • Jean Jordaan
    Jean Jordaan
    2011-11-11

    What do you pass as recipients? It should be a valid list of addresses.
    In the simplest form, that is just a string like:

      name@some.domain.net,   othername@another.domain.net, …

     
  • Giovanni
    Giovanni
    2011-11-11

    I select the recipients from the field To (FieldType: name, settings are Type: Multi valued and Selection mode: Select in a list)

     
1 2 > >> (Page 1 of 2)