Hyper Open Edge Cloud

How To Send A Document

This document provides a description of the future API to send documents.
  • Last Update:2016-05-16
  • Version:001
  • Language:en

This document provides a description of the future API to send documents.

Table of Contents

How to send an Event

event is a CRM event such as an Email or a Fax.

Sending the event:

    event.send()

Let us suppose that the event is a Fax. The script (typed based method) for Fax_send looks like:

   from_url = portal_preferences.getPreferredEmail() 
    # XXX - fix this with appropriate name
  section = portal_preferences.getPreferredGroup()
    # XXX - fix this with appropriate name
  organisation = section.getRepresentingValue()
    # XXX - still no implemented - required to define contact information for a category
  fax_url = organisation.searchFolder(portal_type='Fax', function='communication/fax')
    # XXX - fix this with appropriate name and use of predicates

# XXX -> Why not define this explicitly on the event ? -jerome

  if fax_url is not None: fax_url=fax_url.getUrl()
    # XXX - fix this with appropriate name
  if fax_url is not None:
    message = None
    for destination in context.getDestinationValueList():
      extra_header_dict = {'phone-number': 
        destination.getDefaultFaxValue().asText()} # missing error checking
      message = event.asMIMEMultipart(from_url, fax_url, 
                                      extra_header_dict=extra_header_dict)
      context.MailHost.activate(activity='SQLQueue').sendAndLog(message, document.getPhysicalPath()) # not possible yet
    context.setData(message) # bad error handling
    return
  raise ValueError('No fax gateway defined for %s' % organisation)  

How to build a MIMEMultipart

Let us suppose that the event is a Fax. The script (typed based method) for Even_asMIMEMultipart looks like this (taken from Event_send):

  mail_message = None
  if context.getTextFormat()=='text/html':
  mail_template = context.Event_viewHtmlMimeMessage
  else:
  mail_template = context.Event_viewMimeMessage

  multipart = mail_template.as_message(mfrom=from_url,
                                     mto=to_url,
                                     subject=subject,
                                     body=body,
                                     encoding='utf-8')
  for attachment_dict in attachment_list:
  multipart.add_file(data=attachment_dict['content'],
                     content_type=attachment_dict['mime_type'],
                     filename=attachment_dict['name'])
  mail_message = str(multipart)
  context.activate(activity='SQLQueue').sendMailHostMessage(mail_message)

How to send an Invoice

invoice is a Sales Invoice Transaction.

Sending the invoice XXX does this mean that an invoice (and any other ERP5 document ?) can act as an event ? Why not create an explicit event related to the invoice like we use to do ? -jerome

    invoice.send()

How to print an Invoice

invoice is a Sales Invoice Transaction.

Sending the invoice

    invoice.send(mime_sender=context.portal_printers.printer_1)

Where portal_printers.printer_1 is a subdocument of portal_printers which has been configured to make it possible to print to a given CUPS destination.

Other issues

  • (Missing feature) The current implementation does not support message-id definition. Search about message-id at RFC-822 and Wikipedia. Currently the problem for message-id definition are: We don't generate it and MailTemplate does not support it. does not support it
  • In addition to Message-id, we should also generate "In-Reply-To" and "References" headers in case of email based on causality relation between events, so that mail readers use it for threading of messages.

Related Articles