我正在开发一个Ruby on Rails应用程序,并有一个登台服务器。 但是这个登台服务器不会发送任何电子邮件,而是丢弃它们。
为了testing我们发送的电子邮件,以及这些电子邮件的样子(所以我们可以使用登台服务器进行质量保证),我find了MailCatcher 。 但是目前它专注于开发环境,所以既不支持HTTPS也不支持authentication,而且我也不想公开所有人的MailCatcher电子邮件。
有没有办法通过Apache或Nginx提供HTTPS和基本身份validation? 也许是一个反向代理?
经过一些尝试,并感谢用户mailq提示,我设法使用Apache 2.2 mod_proxy_balancer,mod_proxy和mod_proxy_http来反向代理MailCatcher,能够提供HTTPS和HTTP基本authentication头。
一些设置细节:
/usr/local/rvm/gems/ree-1.8.7-2011.03/gems/mailcatcher-0.5.1/public 。 mailcatcher.example.com 。 /etc/apache2/ssl/mailcatcher.example.com.pem和/etc/apache2/ssl/mailcatcher.example.com.key上创build了自签名证书。 创build一个htpasswd用户/密码文件
mkdir -p /home/deploy/mailcatcher htpasswd -cb /home/deploy/mailcatcher/htpasswd theusername s3cr3t
写入/ 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>
激活所需的Apache模块,网站并重新启动Apache
a2enmod ssl a2enmod proxy_balancer a2enmod proxy_http a2ensite mailcatcher service apache2 restart
打开MailCatcher
mailcatcher --ip 127.0.0.1 --smtp-port 1025 --http-port 1080
我做的最后一件事是configuration我的Ruby on Rails应用程序使用SMTP服务器127.0.0.1, 端口1025 (而不是默认端口25)发送电子邮件。
访问https://mailcatcher.example.com ,用户名为“用户名”和密码“ s3cr3t” 。
也试试http://mailtrap.io – 这是一个基于Web的假SMTP服务器像mailcatcher。 但它并不要求你自己运行SMTP服务器和/或安装Apache。
它具有足够灵活的权限pipe理和授权。