How to Run WebMail under IIS
This scenario is useful in several situations:
- administrator has only one IP and wants to run both IIS and WebMail on port 80
- administrator wants to have a backup solution
- some administrators are very experienced with administration of IIS and want to use that on WebMail too
The WebMail wasn't designed for IIS at the beginning so cannot guarantee full functionality of WebMail under IIS. After numerous tests and with the help of our customers, we discovered that with the changes which are described below all features should work fine.
The following description was done on a test machine with IIS 6.0 and Merak Mail Server 8.2.4.r including the WebMail 5.5.1. It should also work with older versions of Merak (WebMail) and of course, with older versions IIS (ie. 5.1).
Step-by-step description:
1. Editing the WebMail files to be compatible with IIS.
A. Create config.html
Create (or open) the config.html in some text editor. The file should be in the \Merak\ html\mail\ by default. Insert line
<?$SERVER_INSTALL_PATH = 'the real path to your Merak\WebMail installation';?>
so for example <?$SERVER_INSTALL_PATH = 'C:/Program Files/Merak/WebMail/';?>
Attention: there must not be a CRLF after ?> otherwise the attachment will not be displayed correctly
B. Editing fastlog.html file (only for WebMail prior to version 5.5.2)
Open the fastlog.html file which is in Merak\html\mail\ in any text editor and replace this block:
if ($AUTH_USER)
{
$username = $AUTH_USER;
$password = $AUTH_PASSWORD;
}
by this block:
if ($PHP_AUTH_USER)
{
$username = $PHP_AUTH_USER;
$password = $PHP_AUTH_PW;
}
2. Create the Virtual Directory on IIS for WebMail
Start IIS. To do that go to Control Panel -- Administrative Tools and click Internet Information Services (IIS) Manager.

Now list the Default Web Site tree, click right mouse button (or the Action menu) -- New -- Virtual Directory.

The Virtual Directory Creation Wizard will welcome you. Click Next and in the following dialog fill in the Alias. That is the name under which you want to call the virtual directory and how the users will access the WebMail interface under IIS. Let's call it 'WebMail'.
The next dialog wants you to specify the path to the directory where the html files are stored. It is C:\Program files\Merak\HTML\Mail by default. If you install Merak to another directory you will have to choose appropriate path.

Click next and now the permissions definition is requested. Check Read, Run and Execute permissions.
Continue by clicking Next and then Finish buttons to end the Virtual Directory specification.
3. Set the properties for newly created Virtual Directory
After finishing step 1, a new item will appear in the tree. Right-click on it and choose Properties.

In the default Virtual Directory tab click on the Configuration button. Then click on the Add button in the Mappings tab.

In the following dialog browse for the php.exe file that is in the C:\Program Files\Merak\WebMail directory by default and which should be the interpreter for html files, fill in the extension .html to determine for which extension it will work. Please mind that the path to the executable have to be quoted with "".

and confirm it by OK. Then once more click OK to return back to the Properties dialog. After that, choose the Documents tab. Here you have to add a new default document type. Click Add and fill the 'index.html' in the shown dialog

Finish it by clicking OK and move a newly created type at the top of the file types list by clicking on the Move Up button.

Choose the Directory Security tab now and click the Edit button by Anonymous access and authentication control section. Copy the Username which is in the Anonymous access sub-section.

4. Assign appropriate rights for Username
The final step is that you have to set correct permissions for Username which is used for Anonymous Acces to right folders. Set it for these folders:
- %%pathToMerakDirectory%%\WebMail\users
- %%pathToMerakDirectory%%\WebMail\config
- %%pathToMerakDirectory%%\WebMail\sessions
- %%pathToMerakDirectory%%\temp
- %%pathToMerakDirectory%%\html\temp
- %%pathToMerakDirectory%%\Mail
- Windows\temp (this is needed because of attachments - they would be truncated in case this is not set; you can change this folder as it is described at the end of this FAQ)
By default the %%pathToMerakDirectory%% is C:\Program Files\Merak.
The procedure for setting the rights is shown only for the first directory. The others are the same.
Go to Merak\WebMail folder, right-click on the Users directory and choose Properties. Choose the Security tab.
Click Add button and paste the Username which you Copied in the Directory Security tab in IIS Settings.

Click OK and check the Read and Write permissions for that user.

Do the same for other folders listed above.
5. Create new extension for PHP.EXE
Return to IIS Manager and create new extension for the php.exe (WebMail PHP). From the tree select 'Web Service Extensions' -- on the right panel click right mouse button and click 'Add a new Web service extension.

and add (browse) for %%pathToMerakDirectory%%\php\php.exe and allow it (enable the checkbox 'Set extension status to Allowed').

Under IIS of older versions than 6.0, you do not have to create new extension for PHP.EXE
6. Change default port and start the service
Now you need to start the IIS webservice and optionally change the default IIS port (if you want simultaneous webserivces - Merak,IIS, Apache,...). Go to the IIS Manager, in the tree choose 'Web Sites' and with right mouse button click choose 'Properties'. Change the TCP port to whatever you got open. (for example 801).

To start the service simply right-click the Default Web site and press 'Start'

7. See the WebMail under IIS
Check if WebMail is running under IIS properly. You should see the WebMail login screen on this URL:
http://yourIP/WebMail or http://yourHostName/WebMail.

Additional Tips:
- allow Virtual Hosts customization (which is not possible under IIS even after all the changes above)
- Create Virtual Directories under IIS corresponding with your Virtual Hosts. All of them should get the data from html\mail\ folder.
- Edit html\mail\include.html file and the last line below:
<?php
//MSIE check // on JS submit is nullkuli bezpecnosti se tam
testuje /temp/<file>.tmp
if((eregi("MSIE",$HTTP_USER_AGENT) || !$HTTP_USER_AGENT) && !eregi("Opera",$HTTP_USER_AGENT)) $isie=1;
if(eregi("^Mozilla",$HTTP_USER_AGENT) && substr($HTTP_USER_AGENT,strpos($HTTP_USER_AGENT,"/")+1,3)>=5) $ismozilla=1;
// add this line here
$URL = $HTTP_HOST.$PHP_SELF.$QUERY_STRING;
- allow attachments more than 2 MB
Edit wmi.ini file which is Windows folder. Find the line:
upload_max_filesize = 2M
and change the number according to your needs.
Please try to adjust this value if your attachments are not working properly.
- change temp folder for uploading files
By default, WebMail uses Windows system temp folder. It is recommended to change it to WebMail temp folder which is in html\temp folder.
To do that, edit again wmi.ini file and find the line:
;upload_tmp_dir =
delete the semi-colon at the beginning and fill in your path to html\temp folder in your Merak folder. Do not forget to assign permissions to that folder as it is described in point 4.
If you change the temp directory, please note that this new temp have to have name "temp" so for example webmail/temp/ or someting/temp/, etc... (it is because increased security of WebMail)