After some tries, and thanks to user mailq tip, I managed to use Apache 2.2 mod_proxy_balancer, mod_proxy and mod_proxy_http to reverse-proxy MailCatcher, being able to serve HTTPS and HTTP Basic Authentication Headers.
Some setup details:
- Server is running Ubuntu 10.04 LTS
- My mailcatcher gem dir is
/usr/local/rvm/gems/ree-1.8.7-2011.03/gems/mailcatcher-0.5.1/public
.
- My server URL is
mailcatcher.example.com
.
- I created a self-signed certificate on
/etc/apache2/ssl/mailcatcher.example.com.pem
and /etc/apache2/ssl/mailcatcher.example.com.key
.
- My HTTP BasicAuth username is theusername and password is s3cr3t.
- User is called deploy.
- MailCatcher needs to be manually turned on by the deploy user (in other words, Apache won't turn it on on it's own).
Create a htpasswd user/password file
mkdir -p /home/deploy/mailcatcher
htpasswd -cb /home/deploy/mailcatcher/htpasswd theusername s3cr3t
Write to /etc/apache2/sites-available/mailcatcher
<VirtualHost *:443>
ServerName mailcatcher.example.com
DocumentRoot /usr/local/rvm/gems/ree-1.8.7-2011.03/gems/mailcatcher-0.5.1/public
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/mailcatcher.example.com.pem
SSLCertificateKeyFile /etc/apache2/ssl/mailcatcher.example.com.key
<Directory /usr/local/rvm/gems/ree-1.8.7-2011.03/gems/mailcatcher-0.5.1/public>
Allow from all
Options -MultiViews
FileEtag none
</Directory>
<LocationMatch "/">
AuthType Basic
AuthName "MailCatcher"
AuthUserFile /home/deploy/mailcatcher/htpasswd
Require valid-user
</LocationMatch>
RequestHeader set X_FORWARDED_PROTO 'https'
ProxyPassReverse / balancer://mailcatcher
ProxyPreserveHost on
ProxyRequests On
ProxyPass / balancer://mailcatcher/
<Proxy balancer://mailcatcher>
Order deny,allow
Allow from all
BalancerMember http://127.0.0.1:1080
</Proxy>
</VirtualHost>
Activate required Apache modules, site and restart apache
a2enmod ssl
a2enmod proxy_balancer
a2enmod proxy_http
a2ensite mailcatcher
service apache2 restart
Turn MailCatcher on
mailcatcher --ip 127.0.0.1 --smtp-port 1025 --http-port 1080
The last thing I did was to configure my Ruby on Rails app to send email using SMTP server 127.0.0.1, port 1025 (instead of the default port 25).
To accessy https://mailcatcher.example.com, with username theusername and password s3cr3t.