Fix support for send document links and attachments

This commit is contained in:
Roberto Rosario
2014-11-20 02:54:45 -04:00
parent 1950c062b0
commit 173e82684c
2 changed files with 5 additions and 7 deletions

View File

@@ -7,14 +7,12 @@ from mayan.celery import app
@app.task(ignore_result=True)
def task_send_document(subject_text, body_text_content, sender, recipient, document_ids=None):
def task_send_document(subject_text, body_text_content, sender, recipient, document_id, as_attachment=False):
email_msg = EmailMultiAlternatives(subject_text, body_text_content, sender, [recipient])
if document_ids:
documents = [Document.objects.get(pk=document_id) for document_id in document_ids]
for document in documents:
descriptor = document.open()
if as_attachment:
document = Document.objects.get(pk=document_id)
with document.open() as descriptor:
email_msg.attach(document.label, descriptor.read(), document.file_mimetype)
descriptor.close()
email_msg.send()