Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am developing a Ruby on Rails app, and have a staging server. But this staging server isn't sending any emails -- instead, it is discarding them.

In order to test our emails being sent, and how those emails looks like (so we can use the staging server for QA), I found MailCatcher. But currently it is focused on development environment, so there isn't support for neither HTTPS or authentication -- and I don't want to expose all MailCatcher emails for everyone.

Is there any ways to provide HTTPS and basic authentication through Apache or Nginx? Maybe a reverse proxy?

share|improve this question
    
Yes it is possible. See in the upper right corner. There is a search box for "Nginx as reverse proxy", "Apache as HTTPS reverse proxy" or whatever you are trying to do. –  mailq Sep 10 '11 at 20:51
    
Thanks mailq. I managed to do so, and created a tutorial explaining how I did (my answer below). –  jmonteiro Sep 11 '11 at 5:14

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer

Try also http://mailtrap.io - it's a web based fake SMTP server like mailcatcher. But it doesn't require you to run SMTP server yourself and/or setup Apache.

It has permission management and authorization that are flexible enough.

share|improve this answer
    
That's great, mailtrap.io seems to be a cool service for my staging servers. I'll give it a try! –  jmonteiro Feb 23 '12 at 14:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.