add support for direct notifications
This commit is contained in:
parent
c121011edc
commit
e48d1feada
|
@ -1,7 +1,13 @@
|
|||
# -*- coding: utf8 -*-
|
||||
|
||||
import logging
|
||||
import os
|
||||
import os.path
|
||||
|
||||
from email.mime.base import MIMEBase
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
from zope import schema
|
||||
|
||||
from zope.component import queryUtility
|
||||
|
@ -32,6 +38,8 @@ class IImportFileFormSchema(form.Schema):
|
|||
recipient_groups = schema.Text(required=False) # new, comme separated identifiers
|
||||
keywords = schema.Text(required=False) # comma separated identifiers
|
||||
|
||||
notification_recipients = schema.Text(required=False) # comma separated emails
|
||||
|
||||
# legacy
|
||||
treating_group = schema.Text(required=False)
|
||||
|
||||
|
@ -95,3 +103,19 @@ class ImportFileForm(form.SchemaForm):
|
|||
'title': data.get('title'),
|
||||
'keywords': keywords,
|
||||
})
|
||||
|
||||
if data.get('notification_recipients'):
|
||||
document_location = self.request.response.headers['location']
|
||||
subject = 'Nouveau document, %s' % data.get('title')
|
||||
message = 'Ouvrir dans la GED :\n %s\n' % document_location
|
||||
recipients = data.get('notification_recipients').split(',')
|
||||
self.send_message(subject, message, recipients)
|
||||
|
||||
def send_message(self, subject, message, recipients):
|
||||
msg = MIMEMultipart()
|
||||
msg['Subject'] = subject
|
||||
msg['To'] = ', '.join(recipients)
|
||||
msg['From'] = api.portal.get().getProperty('email_from_address') or 'admin@localhost'
|
||||
|
||||
msg.attach(MIMEText(message, _charset='utf-8'))
|
||||
self.context.MailHost.send(msg.as_string())
|
||||
|
|
Reference in New Issue