mailto.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:Kiwi 作者: kiwitcms 项目源码 文件源码
def mailto(template_name, subject, recipients=None,
           context=None, sender=settings.DEFAULT_FROM_EMAIL,
           cc=None):
    # make a list with recipients and filter out duplicates
    if isinstance(recipients, list):
        recipients = list(set(recipients))
    else:
        recipients = [recipients]

    # extend with the CC list
    if cc:
        recipients.extend(cc)

    # if debugging then send to ADMINS as well
    if settings.DEBUG:
        for (admin_name, admin_email) in settings.ADMINS:
            recipients.append(admin_email)

    body = render_to_string(template_name, context)

    email_thread = threading.Thread(
        target=send_mail,
        args=(settings.EMAIL_SUBJECT_PREFIX + subject, body, sender, recipients),
        kwargs={'fail_silently': False}
    )
    # This is to tell Python not to wait for the thread to return
    email_thread.setDaemon(True)
    email_thread.start()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号