• 老广's avatar
    [Update] 修改settings配置 (#2067) · 16cc4a0f
    老广 authored
    * [Update] 修改settings配置
    
    * [Update] 修改settings
    
    * [Update] 修改密码校验规则前后端逻辑
    
    * [Update] 修改用户config机制
    
    * [Update] 修改配置
    
    * [Update] 修改config example增加翻译
    Unverified
    16cc4a0f
tasks.py 992 Bytes
from django.core.mail import send_mail
from django.conf import settings
from celery import shared_task
from .utils import get_logger
from .models import Setting


logger = get_logger(__file__)


@shared_task
def send_mail_async(*args, **kwargs):
    """ Using celery to send email async

    You can use it as django send_mail function

    Example:
    send_mail_sync.delay(subject, message, from_mail, recipient_list, fail_silently=False, html_message=None)

    Also you can ignore the from_mail, unlike django send_mail, from_email is not a require args:

    Example:
    send_mail_sync.delay(subject, message, recipient_list, fail_silently=False, html_message=None)
    """
    if len(args) == 3:
        args = list(args)
        args[0] = settings.EMAIL_SUBJECT_PREFIX + args[0]
        args.insert(2, settings.EMAIL_HOST_USER)
        args = tuple(args)

    try:
        send_mail(*args, **kwargs)
    except Exception as e:
        logger.error("Sending mail error: {}".format(e))