mailbot.rst 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. .. _mailbot:
  2. Setting up the mailbot
  3. ======================
  4. Email Address Settings
  5. ----------------------
  6. The first step is to configure the project to use email addresses of your
  7. choosing. You should modify the following values in
  8. ``distro_tracker/project/settings/local.py``:
  9. * DISTRO_TRACKER_CONTROL_EMAIL
  10. This is the email address which is to be used for receiving control
  11. messages.
  12. * DISTRO_TRACKER_CONTACT_EMAIL
  13. This is the email address from which the mailbot responds.
  14. * DISTRO_TRACKER_FQDN
  15. The fully qualified domain name which will receive package related messages.
  16. Package messages will be sent to ``<package_name>@<DISTRO_TRACKER_FQDN>``.
  17. .. note::
  18. These emails are allowed to be on different domains.
  19. Management commands
  20. -------------------
  21. In order to have the received email messages properly processed they need to
  22. be passed to the following management commands:
  23. * :mod:`distro_tracker_control <distro_tracker.mail.management.commands.tracker_control>` - handles control messages
  24. * :mod:`distro_tracker_dispatch <distro_tracker.mail.management.commands.tracker_dispatch>` - handles package messages
  25. * :mod:`distro_tracker_receive_news <distro_tracker.mail.management.commands.tracker_receive_news>` -
  26. handles messages which should be turned into news items
  27. These commands expect the received email message on standard input, which
  28. means that the system's MTA needs to be setup to forward appropriate mails to
  29. the appropriate command.
  30. Exim4
  31. -----
  32. Mails received to ``DISTRO_TRACKER_CONTROL_EMAIL`` address should be piped to the
  33. ``control_process`` command. A way to set this up in Exim would be to create a
  34. new alias for the local part of the control email address and set it to point
  35. to the user who owns the Distro Tracker application. That user should have a ``.forward``
  36. file in his home directory which includes the directive to pipe incoming email
  37. to the command.
  38. For example, if the ``DISTRO_TRACKER_CONTROL_EMAIL`` is set to ``control@distro_tracker.debian.net``
  39. and the system user which owns the application is called ``dtracker`` the contents of
  40. ``/etc/aliases`` should include the following line::
  41. control: dtracker
  42. And the ``.forward`` file should be::
  43. | python path/to/manage.py distro_tracker_control
  44. Mails received at ``DISTRO_TRACKER_CONTACT_EMAIL`` should be saved or forwarded to the
  45. Distro Tracker administrators. This can be done by adding an additional alias to
  46. ``/etc/aliases/``. For example, if ``DISTRO_TRACKER_CONTACT_EMAIL`` is set to
  47. ``owner@distro_tracker.debian.net``, the line in the aliases file would be::
  48. owner: some-admin-user
  49. All mail addresses at the ``DISTRO_TRACKER_FQDN`` domain (apart from ``DISTRO_TRACKER_CONTROL_EMAIL``
  50. and ``DISTRO_TRACKER_CONTACT_EMAIL`` addresses if they are on that domain), are considered
  51. package names. As such, all of them should be piped to the ``dispatch``
  52. management command so that they can be processed by Distro Tracker.
  53. To set this up, a custom router and transport can be added to exim
  54. configuration which acts as a catchall mechanism for any email addresses which
  55. are not recognized. Such router and transport could be::
  56. distro_tracker_package_router:
  57. debug_print = "R: Distro Tracker catchall package router for $local_part@$domain"
  58. driver = accept
  59. transport = distro_tracker_dispatch_pipe
  60. distro_tracker_dispatch_pipe:
  61. driver = pipe
  62. command = python /path/to/manage.py distro_tracker_dispatch
  63. user = dtracker
  64. group = mail
  65. log_output
  66. .. note::
  67. This router should be placed last in the exim configuration file.
  68. Postfix
  69. -------
  70. To configure Postfix to forward email messages to appropriate commands you need
  71. to first create a file with virtual aliases for the relevant email addresses.
  72. Assuming the following configuration::
  73. DISTRO_TRACKER_CONTACT_EMAIL = owner@distro_tracker.debian.net
  74. DISTRO_TRACKER_CONTROL_EMAIL = control@distro_tracker.debian.net
  75. DISTRO_TRACKER_FQDN = distro_tracker.debian.net
  76. The file ``/etc/postfix/virtual`` would be::
  77. distro_tracker.debian.net not-important-ignored
  78. postmaster@distro_tracker.debian.net postmaster@localhost
  79. owner@distro_tracker.debian.net dtracker-owner@localhost
  80. control@distro_tracker.debian.net dtracker-control@localhost
  81. _news@distro_tracker.debian.net dtracker-news@localhost
  82. # Catchall for package emails
  83. @distro_tracker.debian.net dtracker-dispatch@localhost
  84. The ``/etc/aliases`` file should then include the following lines::
  85. dtracker-owner: some-admin-user
  86. dtracker-control: "| python /path/to/manage.py distro_tracker_control"
  87. dtracker-dispatch: "| python /path/to/manage.py distro_tracker_dispatch"
  88. dtracker-news: "| python /path/to/manage.py distro_tracker_receive_news"
  89. Then, the ``main.cf`` file should be edited to include::
  90. virtual_alias_maps = hash:/etc/postfix/virtual
  91. .. note::
  92. Be sure to run ``newaliases`` and ``postmap`` after editing ``/etc/aliases``
  93. and ``/etc/postfix/virtual``.
  94. This way, all messages which are sent to the owner are delivered to the local
  95. user ``some-admin-user``, messages sent to the control address are piped to
  96. the ``distro_tracker_control`` management command, mesages which should be turned into
  97. news items to the ``distro_tracker_receive_news`` command and messages sent to any other
  98. address on the given domain are passed to the ``distro_tracker_dispatch`` management
  99. command.