Skip to content

Instantly share code, notes, and snippets.

@pitpit
Last active November 21, 2022 04:45
Show Gist options
  • Star 29 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save pitpit/78fc6b34b1b564c86d80 to your computer and use it in GitHub Desktop.
Save pitpit/78fc6b34b1b564c86d80 to your computer and use it in GitHub Desktop.
Install Mailcatcher on OSX - works well with macOS Sierra High 10.12.X

05/25/2018: tested with macOS Sierra High 10.12.6

08/04/2020: added @mayesa's suggestion to fix an exception with EventMachine 08/04/2020: tested with macOS Catalina 10.15.5

Install MailCatcher:

brew install ruby
sudo gem install mailcatcher

Run:

mailcatcher &

Or set it up a daemon.

To set it up for PHP: edit php.ini (on OSX brew, /usr/local/etc/php/5.5/conf.d/mailcatcher.ini) and paste the following configuration:

sendmail_path = /usr/bin/env /usr/local/bin/catchmail -f catcher@mailcatcher.me

put any email you want instead of catcher@mailcatcher.me

To test it:

php -r "mail('john.doed@test.fr', 'test', 'test');"

Then, visit the mailcatcher backend : http://localhost:1080

Troubleshoot

  • If you got a 'require': cannot load such file -- i18n/core_ext/string/interpolate (LoadError) exception, run:
sudo gem uninstall i18n
sudo gem install i18n -v 0.6.11
sudo gem install interpolate

(see sj26/mailcatcher#155)

  • If you got an Unable to load the EventMachine C extension exception, run:
sudo gem uninstall mailcatcher eventmachine
sudo gem install mailcatcher
@pitpit
Copy link
Author

pitpit commented Jun 23, 2015

Symfony2 Swiftmailer configuration with mailcatcher:

swiftmailer:
   transport:  smtp
   host:       localhost:1025
   username:   null
   password:   null
   #port:       %mailer_port%
   #encryption: %mailer_encryption%
   #spool:      { type: memory }

@Tantuss
Copy link

Tantuss commented Oct 14, 2015

In case you get this error (probably because of El Capitan upgrade):
.....
checking for gethrtime()... no
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling binder.cpp
In file included from binder.cpp:20:
./project.h:116:10: fatal error: 'openssl/ssl.h' file not found

include <openssl/ssl.h>

     ^

1 error generated.
make: *** [binder.o] Error 1

make failed, exit code 2

Install it like this:
gem install mailcatcher -- --with-cppflags=-I/usr/local/opt/openssl/include

@irvins
Copy link

irvins commented Oct 26, 2015

Thank you Tantuss , that was exactly the problem i was running into.

@blanco217
Copy link

Thanks Tantuss that helped with my problem

@kirkgale
Copy link

@Tantuss you rock, that fixed it for me as well.

@juukie
Copy link

juukie commented May 25, 2016

Not sure why but I had to copy mailcatcher and catchmail from /usr/local/Cellar/ruby/2.0.0-p247/bin to /usr/local/opt/bin to get it working. On my other iMac I did not have to copy the files. Probably the ruby version did it (other iMac had version 2.3.1).

@FlorinMotoc
Copy link

On macOS Sierra (only sudo gem install mailcatcher run, without brew ruby), correct line is:

sendmail_path = /usr/bin/env /usr/local/bin/catchmail -f catcher@mailcatcher.me

It didn't worked for me any other way.

@rupokify
Copy link

rupokify commented Dec 14, 2016

On macOS Sierra (only sudo gem install mailcatcher run, without brew ruby), correct line is:

sendmail_path = /usr/bin/env /usr/local/bin/catchmail -f catcher@mailcatcher.me

It didn't worked for me any other way.

@FlorinMotoc You just saved my day buddy! Thanks a ton.

@rordi
Copy link

rordi commented Jan 3, 2017

To use with CakePHP 3, adjust config/app.php:

 'EmailTransport' => [
	'mailcatcher' => [
		'className' => 'Smtp',
		'host' => 'localhost',
		'port' => 1025,
	],
 ],

and

'Email' => [
    'default' => [
        'transport' => 'mailcatcher',
        'from' => 'anything@here.com',
        'charset' => 'utf-8',
        'headerCharset' => 'utf-8',
    ],
],

@ahules
Copy link

ahules commented Mar 25, 2017

Hello, I installed mailcatcher using command:
sudo gem install mailcatcher
Then create /mailcatcher.ini
and put there "sendmail_path = /usr/bin/env catchmail -f catcher@mailcatcher.me"

But "mailcatcher" catch mail only when I send email from cli.
Like this: php -r "mail('john.doed@test.fr', 'test', 'test');"
When i try send email via script from browser mail function returns false.

Can you help how to fix this behavior?

@jeremiahsmall
Copy link

Perfect solution for testing a legacy app with the built in php server. Thx!

@matthewhaworth
Copy link

matthewhaworth commented Jan 11, 2018

Not sure if anyone had an issue on Macs, but I had a problem on Mac OS Sierra. I changed

sendmail_path = /usr/bin/env catchmail -f catcher@mailcatcher.me
to
sendmail_path = /usr/bin/env /usr/local/bin/catchmail -f catcher@mailcatcher.me

and it worked!

@reillo
Copy link

reillo commented May 3, 2018

If you're having issue on CLI or Unit testing. Make sure that
php -i | grep sendmail_path returns the correct configuration of mailcathcer.

@ahmadmayahi
Copy link

For Symfony 4+ usage, modify .env file as follows:
MAILER_URL=smtp://localhost:1025

@ernestjumbe
Copy link

Tanks so much for this. I had almost given up.

@chrisVdd
Copy link

For Symfony 4+ usage, modify .env file as follows:
MAILER_URL=smtp://localhost:1025

And start from Symfony 4.3, if you use the new Symfony Mailer component:

MAILER_DSN=smtp://localhost:1025

@radrr
Copy link

radrr commented May 27, 2020

Hi i have installed mailcatcher using the standard 'brew' and 'gem' approach described above. During the past year everything worked fine, but quite recently (using MacOS Catalina 10.15.4) i started getting following error message and i'm unable to start mailcatcher:

Unable to load the EventMachine C extension; To use the pure-ruby reactor, require 'em/pure_ruby' Traceback (most recent call last): 10: from /usr/local/bin/mailcatcher:23:in '<main>' 9: from /usr/local/bin/mailcatcher:23:in 'load' 8: from /Library/Ruby/Gems/2.6.0/gems/mailcatcher-0.7.1/bin/mailcatcher:3:in '<top (required)>' 7: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in 'require' 6: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in 'require' 5: from /Library/Ruby/Gems/2.6.0/gems/mailcatcher-0.7.1/lib/mail_catcher.rb:15:in '<top (required)>' 4: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in 'require' 3: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in 'require' 2: from /Library/Ruby/Gems/2.6.0/gems/eventmachine-1.0.9.1/lib/eventmachine.rb:8:in '<top (required)>' 1: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in 'require' /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in 'require': dlopen(/Library/Ruby/Gems/2.6.0/gems/eventmachine-1.0.9.1/lib/rubyeventmachine.bundle, 0x0009): dependent dylib '/usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib' not found for '/Library/Ruby/Gems/2.6.0/gems/eventmachine-1.0.9.1/lib/rubyeventmachine.bundle' - /Library/Ruby/Gems/2.6.0/gems/eventmachine-1.0.9.1/lib/rubyeventmachine.bundle (LoadError)

@mayesa
Copy link

mayesa commented Jun 1, 2020

Same here

@mayesa
Copy link

mayesa commented Jun 1, 2020

@radrr I fixed the above error by running

sudo gem uninstall mailcatcher eventmachine
sudo gem install mailcatcher

@radrr
Copy link

radrr commented Jun 1, 2020

@radrr I fixed the above error by running

sudo gem uninstall mailcatcher eventmachine
sudo gem install mailcatcher

Hey Mayesa, you have solved the issue, mailcatcher now runs again as a charm :) many thanks!

@blockerdude
Copy link

Can also confirm that @mayesa's solution works.

@yojeek
Copy link

yojeek commented Nov 4, 2020

To fix build issues with Catalina:

gem install thin -v 1.5.1 -- --with-cflags="-Wno-error=implicit-function-declaration"
gem install mailcatcher

source

@Jliv316
Copy link

Jliv316 commented Mar 2, 2021

@mayesa's solution works

@sylow
Copy link

sylow commented Mar 18, 2021

gem install thin -v 1.5.1 -- --with-cflags="-Wno-error=implicit-function-declaration"

This is what worked for me on Mac M1. Thank you

@itschrislow
Copy link

itschrislow commented Jun 25, 2021

gem install thin -v 1.5.1 -- --with-cflags="-Wno-error=implicit-function-declaration"

Works on OS Big Sur. Thank you!

@metallurgical
Copy link

To fix build issues with Catalina:

gem install thin -v 1.5.1 -- --with-cflags="-Wno-error=implicit-function-declaration"
gem install mailcatcher

source

works on Big Sur!

@rubywarlock
Copy link

macOS Monterey work:

gem install thin -v 1.5.1 -- --with-cflags="-Wno-error=implicit-function-declaration"
gem install mailcatcher

@laurentfontaine1967
Copy link

Got this with my macbook air on Monterey:

ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.
macbookair@macbooks-air ~ %

@sunwooz
Copy link

sunwooz commented Nov 21, 2022

To fix build issues with Catalina:

gem install thin -v 1.5.1 -- --with-cflags="-Wno-error=implicit-function-declaration"
gem install mailcatcher

source

Worked on Monterey, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment