summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVasil Vangelovski <vvangelovski@gmail.com>2012-01-31 19:38:36 +0100
committerVasil Vangelovski <vvangelovski@gmail.com>2012-01-31 19:38:36 +0100
commit4c2851f37e2c1504bfce8735544d208158f31d72 (patch)
tree0e6ebc1d375a3c681041fd541c892361ff913934
parentd946e0b55332d96f3ba6281db1d5218e80c0f0d2 (diff)
downloadaskbot-4c2851f37e2c1504bfce8735544d208158f31d72.tar.gz
askbot-4c2851f37e2c1504bfce8735544d208158f31d72.tar.bz2
askbot-4c2851f37e2c1504bfce8735544d208158f31d72.zip
Forward rules for reply by email
-rw-r--r--askbot/doc/source/optional-modules.rst27
-rw-r--r--askbot/lamson_handlers.py12
2 files changed, 35 insertions, 4 deletions
diff --git a/askbot/doc/source/optional-modules.rst b/askbot/doc/source/optional-modules.rst
index b574aeae..0c013121 100644
--- a/askbot/doc/source/optional-modules.rst
+++ b/askbot/doc/source/optional-modules.rst
@@ -173,12 +173,13 @@ Askbot supports posting replies by email. For this feature to work ``Lamson`` a
pip install django-lamson
-The lamson daemon needs a folder to store it's mail queue files, create a folder named ``run`` within your project folder by executing the following command:
+The lamson daemon needs a folder to store it's mail queue files and a folder to store log files, create the folders folder named ``run`` and ``logs`` within your project folder by executing the following commands:
mkdir run
-The minimum settings required to enable this feature are defining the port and binding address for the lamson SMTP daemon and the
-and the email handlers withing askbot. Edit your settings.py file to include the following:
+ mkdir logs
+
+The minimum settings required to enable this feature are defining the port and binding address for the lamson SMTP daemon and the email handlers within askbot. Edit your settings.py file to include the following:
LAMSON_RECEIVER_CONFIG = {'host': 'your.ip.address', 'port': 25}
@@ -203,8 +204,26 @@ Note that in order to be able to bind the daemon to port 25 you will need to exe
Within the askbot admin interface there are 4 significant configuration points for this feature.
* In the email section, the "Enable posting answers and comments by email" controls whether the feature is enabled or disabled.
-* The "reply by email hostname" needs to be set to the email hostname where you want to receive the email replies. If for example this is set to "myaskbot.com" the users will post replies to addresses such as "4wffsw345wsf@myaskbot.com", you need to point the MX DNS record for that domain to the address where you will run the lamson SMTP daemon.
+* The "reply by email hostname" needs to be set to the email hostname where you want to receive the email replies. If for example this is set to "example.com" the users will post replies to addresses such as "4wffsw345wsf@example.com", you need to point the MX DNS record for that domain to the address where you will run the lamson SMTP daemon.
* The last setting in this section controls the threshold for minimum length of the reply that is posted as an answer to a question. If the user is replying to a notification for a question and the reply body is shorter than this threshold the reply will be posted as a comment to the question.
* In the karma thresholds section the "Post answers and comments by email" defines the minimum karma for users to be able to post replies by email.
+If the system where lamson is hosted also acts as an email server or you simply want some of the emails to be ignored and sent to another server you can define forward rules. Any emails matching these rules will be sent to another smtp server, bypassing the reply by email function. As an example by adding the following in your settings.py file:
+
+ LAMSON_FORWARD = (
+ {
+ 'pattern': '(.*?)@(.subdomain1|subdomain2)\.example.com',
+ 'host': 'localhost',
+ 'port': 8825
+ },
+ {
+ 'pattern': '(info|support)@example.com',
+ 'host': 'localhost',
+ 'port': 8825
+ },
+
+ )
+
+any email that was sent to anyaddress@sobdomain1.example.com or anyaddress@sobdomain2.example.com or info@example.com will be forwarded to the smtp server listening on port 8825. The pattern parameter is treated as a regular expression that is matched against the ``To`` header of the email message and the ``host`` and ``port`` are the host and port of the smtp server that the message should be forwarded to.
+
If you want to run the lamson daemon on a port other than 25 you can use a mail proxy server such as ``nginx`` that will listen on port 25 and forward any SMTP requests to lamson. Using nginx you can also setup more complex email handling rules, such as for example if the same server where askbot is installed acts as an email server for other domains you can configure nginx to forward any emails directed to your askbot installation to lamson and any other emails to the mail server you're using, such as ``postfix``. For more information on how to use nginx for this please consult the nginx mail module documentation `nginx mail module documentation <http://wiki.nginx.org/MailCoreModule>`_ .
diff --git a/askbot/lamson_handlers.py b/askbot/lamson_handlers.py
index d91749c8..c39df01a 100644
--- a/askbot/lamson_handlers.py
+++ b/askbot/lamson_handlers.py
@@ -1,9 +1,11 @@
import re
import logging
from lamson.routing import route, route_like, stateless
+from lamson.server import Relay
from django.utils.translation import ugettext as _
from askbot.models import ReplyAddress
from askbot.conf import settings as askbot_settings
+from django.conf import settings
@@ -42,6 +44,15 @@ def _strip_message_qoute(message_text):
@route("(address)@(host)", address=".+")
@stateless
def PROCESS(message, address = None, host = None):
+ try:
+ for rule in settings.LAMSON_FORWARD:
+ if re.match(rule['pattern'], message.base['to']):
+ relay = Relay(host=rule['host'],
+ port=rule['port'], debug=1)
+ relay.deliver(message)
+ return
+ except AttributeError:
+ pass
error = None
try:
@@ -73,3 +84,4 @@ def PROCESS(message, address = None, host = None):
)
+