mails.rst 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. =============
  2. Sending Mails
  3. =============
  4. Misago provides its own API for sending e-mails to forum users that extends standard `Django mailer <https://docs.djangoproject.com/en/dev/topics/email/>`_.
  5. This API lives in :py:mod:`misago.core.mail` and provides following functions:
  6. build_mail
  7. ----------
  8. .. function:: build_mail(request, recipient, subject, template, context=None)
  9. Build e-mail message using supplied template name and (optionally) context. Template name shouldn't contain file extension, as Misago will automatically append ``.html`` for html content and ``.txt`` for plaintext content of the message. Message templates will have access to same request context as other templates, additional context you've provided and two extra context values: ``recipient`` and ``sender``.
  10. * ``request:`` HttpRequest object instance.
  11. * ``recipient:`` User model instance.
  12. * ``subject:`` A string.
  13. * ``template:`` A string.
  14. * ``context:`` The optional dictionary with extra context values that should be available for message templates.
  15. mail_user
  16. ---------
  17. .. function:: mail_user(request, recipient, subject, template, context=None)
  18. Shortcut function that calls ``build_mail`` to build message, then sends it to user.
  19. * ``request:`` HttpRequest object instance.
  20. * ``recipient:`` User model instance.
  21. * ``subject:`` A string.
  22. * ``template:`` A string.
  23. * ``context:`` The optional dictionary with extra context values that should be available for message templates.
  24. mail_users
  25. ----------
  26. .. function:: mail_users(request, recipients, subject, template, context=None)
  27. Same as above, but instead of sending message to one recipient, it sends it to many recipients at same time. Keep on mind this may be memory intensitive as this function creates one Mail object instance for every recipient specified, so you may want to split recipients into smaller groups as you are sending them emails.
  28. * ``request:`` HttpRequest object instance.
  29. * ``recipients:`` Iterable of User models.
  30. * ``subject:`` A string.
  31. * ``template:`` A string.
  32. * ``context:`` The optional dictionary with extra context values that should be available for message templates.