I have found a way to help SmarterMail see the correct IP address when there is a web proxy in front of SmarterMail. My proxies report front to back: clientip,+proxy1,+proxy2. I have the impression that some products may change the order. If yours is different, you will need to modify my regex.
This process modifies the web.config file in C:\Program Files (x86)\SmarterTools\SmarterMail\MRS, assuming you have SmarterMail installed in default directories.
I just got this working, have not yet put it into production, but so excited that I had to share. Do your own testing as well.
1) Make a backup of your web.config file.
2) Create a new server variable:
In IIS, navigate to Sites\<smartermailsite>\Url Rewrite
On the right hand side, choose "View Server Variables"
After the page changes, on the right hand side choose "Add..."
Server Variable Name: HTTP_X_PROXIEDIP
3) Add a new URL rewrite rule to populate the new variable. It needs to be the first rule, because the rule provided by SmarterMail says to stop processing after it is triggered. (You can create the rule anywhere. After the rule is created, you can use the link on the right side to move your rule up to the top.) Here are the settings for configuring the rewrite rule using the GUI:
Name: DetectProxy
Requested URL: Matches the pattern
Using: Regular Expressions
Pattern: (.*)
Ignore case: has no effect since you are matching to a wildcard. Suggest no for performance.
Conditions:
Logical Grouping: (Match Any or Match All) has no effect for this example because I am only defining one condition.
[Add] a condition: {HTTP_X_FORWARDED_FOR} matches the pattern ^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}
This extracts the first IPv4 address into token {C:0}
Again, case does not matter since we are only capturing numbers and periods.
Server Variables:
[Add] a variable: HTTP_X_PROXIEDIP value {C:0} Replace the existing value: Checked
Action Type: None
Stop processing of subsequent rules: UNCHECKED (so that the SmarterMail rule will be processed).
On the right side, click "Apply" to save your work.
The changes to your web.config file should look like this. Bold users can just edit the file directly.
<rule name="DetectProxy">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{HTTP_X_FORWARDED_FOR}" pattern="^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" />
</conditions>
<serverVariables>
<set name="HTTP_XEXTERNALFLAG" value="PROXIED" />
<set name="HTTP_X_PROXIEDIP" value="{C:0}" />
</serverVariables>
<action type="None" />
</rule>
3) Test your regex without changing behavior:
Navigate to Sites/<smartermailsite>\Logging
In the Format section, click [Select Fields]
In the bottom of the pop-up form, click [Add Field]
Field Name: HTTP_X_PROXIEDIP
Source Type: Server Variable
Source: HTTP_X_PROXIEDIP
Before testing, I suggest reinitializing your log files. Stop the SmarterMail website and IIS, delete any logs that are not needed, then restarting everything. Run a test and review the IIS logs to verify that the correct IP address is put into that variable.
4) After succesful tests, go live:
In IIS, navigate to <servername>\Application Request Routing Cache.
On the right side, click "Server Proxy Settings"
in the middle of the form, change "Preserve client IP in the following header:
from: X-Forwarded-For
to: x-proxied-ip
Restart everything to be sure that the changes take effect.
Log in and out of SmarterMail.
Check the Administrative log to confirm that the logged IP address is the client IP rather than the web proxy IP.
Note: When the connection is direct (no proxy), the X-Forwarded-For header does not exist, so any attempt to test on its value will fail.