Skip to content

Instantly share code, notes, and snippets.

@dharma017
Created September 14, 2015 05:21
Show Gist options
  • Save dharma017/ed4f232ac80894f201f6 to your computer and use it in GitHub Desktop.
Save dharma017/ed4f232ac80894f201f6 to your computer and use it in GitHub Desktop.
Email Debugging with MailCatcher

#MailCatcher

MailCatcher runs a super simple SMTP server which catches any message sent to it to display in a web interface. Run mailcatcher, set your favourite app to deliver to smtp://127.0.0.1:1025 instead of your default SMTP server, then check out http://127.0.0.1:1080 to see the mail that's arrived so far.

Manually Installing MailCatcher

sudo apt-get install -y vim curl python-software-properties lynx nginx
sudo apt-get install -y php5-fpm php5-memcache memcached php-apc
sudo apt-get install -y build-essential libsqlite3-dev ruby1.9.3
sudo gem install mailcatcher

Failed to build gem native extension

apt-get install ruby-dev

Install Mailcatcher as a Ruby gem

sudo gem install mailcatcher

Then we can can start using Mailcatcher. We'll bind the web interface's IP address to all networks:

mailcatcher --foreground --http-ip=0.0.0.0

This will run Mailcatcher in the foreground. You can exit it by hitting Ctrl+C.

Local scripts can then connect to SMTP at localhost port 1025. Additionally, the web interface is available at port 1080 by default.

###Sample Example in Codeigniter

$config = array();
$config['useragent']           = "CodeIgniter";
$config['mailpath']            = "/usr/bin/sendmail"; // or "/usr/sbin/sendmail"
$config['protocol']            = "smtp";
$config['smtp_host']           = "localhost";
$config['smtp_port']           = "1025";
$config['mailtype'] = 'html';
$config['charset']  = 'utf-8';
$config['newline']  = "\r\n";
$config['wordwrap'] = TRUE;

$this->load->library('email');

$this->email->initialize($config);

$this->email->from($fromEmail, $fromName);
$this->email->to($email);

$this->email->subject('Теst Email');
$this->email->message($this->load->view('email/'.$type.'-html', $data, TRUE));       
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment