# Copyright 2020 Karlsruhe Institute of Technology
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from flask import current_app
import kadi.lib.constants as const
from .core import send_mail
from kadi.ext.celery import celery
from kadi.lib.tasks.core import launch_task
@celery.task(name=const.TASK_SEND_MAIL, max_retries=5, bind=True)
except ConnectionRefusedError as e:
# Catches retry exceeded exceptions as well.
except Exception as e:
"""Send a mail in a background task.
See :func:`kadi.lib.mails.core.send_mail` for the possible parameters.
In case the connection to the mail server fails, the task will be retried every 60
seconds until a maximum defined in ``CELERY_ANNOTATIONS`` in the application's
configuration is reached. Other errors will cause the task to fail, however.
:return: ``True`` if the task was started successfully, ``False`` otherwise. Note
that the task being started successfully does not necessarily mean that the
email will be sent successfully as well.