summaryrefslogtreecommitdiffstats
path: root/src/collective/dms/batchimport/fileimporter.py
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2018-05-31 05:16:52 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2018-05-31 05:16:52 (GMT)
commite48d1feadabd35caef0b5192e79ca50f1bdc5b81 (patch)
treee7438504ce2d269cd9908d9f458d1b3112198bff /src/collective/dms/batchimport/fileimporter.py
parentc121011edc88c19f7d22e6ce4d90a00c447e2087 (diff)
downloadcollective.dms.batchimport-e48d1feadabd35caef0b5192e79ca50f1bdc5b81.zip
collective.dms.batchimport-e48d1feadabd35caef0b5192e79ca50f1bdc5b81.tar.gz
collective.dms.batchimport-e48d1feadabd35caef0b5192e79ca50f1bdc5b81.tar.bz2
add support for direct notificationsHEADmaster
Diffstat (limited to 'src/collective/dms/batchimport/fileimporter.py')
-rw-r--r--src/collective/dms/batchimport/fileimporter.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/collective/dms/batchimport/fileimporter.py b/src/collective/dms/batchimport/fileimporter.py
index 558f75d..3af748b 100644
--- a/src/collective/dms/batchimport/fileimporter.py
+++ b/src/collective/dms/batchimport/fileimporter.py
@@ -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())