Server-Side Email on OS X
This will make it so that you can send email from Terminal sessions, server-side scripts, and web pages. We are also going to tell it to route email through your ISP's email servers: Gmail, in this case.
Works on: OS 10.5 and 10.6
Conveniently, the powerful and popular SMTP server, Postfix, is already installed on OS X. In this example, we're going to tell it to route outgoing email through your Gmail account.
Edit Postfix's config file:
sudo nano /etc/postfix/main.cf
Esc-/ to go to the bottom of the file. Add the block of text below to the bottom, changing
relayhost to your outgoing SMTP-server address. In this example, we are using port 587, which TLS-encrypted mail travels through. Verify your ISP supports TLS and port 587. Nearly all do.
relayhost = smtp.gmail.com:587 smtp_sasl_auth_enable = yes smtp_use_tls = yes smtp_enforce_tls = yes smtp_sasl_security_options = smtp_sasl_tls_security_options = smtp_sasl_tls_verified_security_options = smtp_tls_loglevel = 2 # Log is here /var/log/mail.log smtp_sasl_password_maps = hash:/etc/postfix/smtp_sasl_passwords smtp_tls_per_site = hash:/etc/postfix/smtp_tls_sites tls_random_source = dev:/dev/urandom
Create the file to hold login credentials:
sudo nano /etc/postfix/smtp_sasl_passwords
Add this line to it, changing it to match your SMTP server address and credentials:
Edit this file:
sudo nano /etc/postfix/smtp_tls_sites
Add this line to it, changing mail server accordingly:
Run these commands:
cd /etc/postfix sudo chmod go-rx smtp_sasl_passwords sudo postmap smtp_sasl_passwords sudo postmap smtp_tls_sites
Change email addresses to yours:
echo "Hello" | mail -s "Test" firstname.lastname@example.org
The above may not work if your ISP requires a valid From address, so also try:
printf "Subject: TestnHello" | sendmail -f email@example.com firstname.lastname@example.org
Both of these worked with Gmail, in my case.
If things fail, tail out the log:
tail -f /var/log/mail.log
Send more email in a new Terminal tab while watching the logs.
Filed under Mac