Search code examples
python-2.7django-1.8django-notification

how to send mail notification automatically using django modules?


I'm developing an app which control phone consumption, and i want to make a notification system that notifies employers automatically when they reach a consumption rate.the employers are not included in the auth_user, and all notifications modules i found work with auth_user table. so can any one propose a module who satisfies my needs and thanks


Solution

  • You don't need to have a registered user to send an email notification (which is what I understand you want to accomplish).

    See Django email documentation: https://docs.djangoproject.com/en/1.8/topics/email/

    Instead of defining the content as plain text, you can use an HTML template like any other page in your website (or as well for the plain text version).

    E.g For sending a plain text email using a template :

    from django.template.loader import render_to_string
    from django.core.mail import send_mail
    email_message = render_to_string(template_path, template_context)
    send_mail(subject, email_message, sender_email, [recipient_email])