This is a quick note in how to use msmtp to send email messages using gmail.
Actually configuring msmtp in OSX is almost the same steps on Linux variants.
Lets get started, i'll be using msmtp on
macports. (Install macports first)
Launch a terminal app, and install msmtp.
taeness:~magictalong: sudo port install msmtp
We also need certificates, so install curl-ca-bundle
taeness:~ magictalong: sudo port install curl-ca-bundle
Create a msmtp configuration in your home directory. (By default msmtp uses /opt/local/etc/msmtprc if a user file configuration does not exists)
taeness:~ magictalong: touch /Users/magictalong/.msmtprc
Launch your favorite editor, copy the default account configuration.
taeness:~ magictalong: vim /Users/magictalong/.msmtprc
account default
port 587
timeout 30
auth on
password maypassword
auto_from off
from testing
tls on
tls_starttls on
tls_trust_file /opt/local/share/curl/curl-ca-bundle.crt
logfile /var/log/msmtp.log
If you want to enable logging, be sure the file on the logfile option exists,
and have read and write permission.
Change mode the msmtp configuration file no more than user read/write permission
taeness:~ magictalong: chmod 600 /Users/magictalong/.msmtprc
Test msmtprc
taeness:~ magictalong: echo "Hello There" > ~/some_text.txt
Configure your php.ini file, and in the sendmail path option:
sendmail_path = /opt/local/bin/msmtp -C /Users/magictalong/.msmtprc -t
Change the configuration file permission, so the web server could access the configuration file.
Example: My apache web server is invoke via user "nobody", so:
taeness:~ magictalong: chown nobody /Users/magictalong/.msmtprc
Test sending via Php, (I'm using XAMPP as an example, and the test_email.php is a simple email script using the mail function)
taeness:~ magictalong: sudo /Applications/XAMPP/xamppfiles/bin/php -f ~/Projects/test_email.php
taeness:~ magictalong: Email Sent!
If it doesnt work, check the apache error log for details.