Files
mayan-edms/mayan/apps/mailer/tasks.py
Roberto Rosario a72ac6eadb Add user mailer backends support. GitLab issue #286.
Add support for creating dynamic forms.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
2017-07-03 13:37:56 -04:00

38 lines
1.1 KiB
Python

from __future__ import unicode_literals
from django.apps import apps
from django.core.mail import EmailMultiAlternatives
from documents.models import Document
from mayan.celery import app
@app.task(ignore_result=True)
def task_send_document(subject_text, body_text_content, sender, recipient, document_id, user_mailer_id, as_attachment=False):
UserMailer = apps.get_model(
app_label='mailer', model_name='UserMailer'
)
user_mailer = UserMailer.objects.get(pk=user_mailer_id)
connection = user_mailer.get_connection()
email_msg = EmailMultiAlternatives(
subject_text, body_text_content, sender, [recipient],
connection=connection,
)
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
)
try:
email_msg.send()
except Exception as exception:
user_mailer.error_log.create(message=exception)
else:
user_mailer.error_log.all().delete()