Doing mail from the Command Line is not as hard as you may think.

To send an email from your computer just open Terminal and type the following command:


mail -s "Subject" [email protected] <<EOF



Replace “Subject” with the subject of the mail messages that you are sending. You’ll then replace “[email protected]” with the email address of the recipient of the message. Finally, to write your message, include the <<EOF, followed by an enter, then type your message using as many newline characters as needed. When you are ready to stop writing and send your message, type “EOF” followed by the enter key.

A 1 Line method would look like this:

echo 'Some Text of the Body!'  | mail -s 'Subject!' [email protected]


(notice the use of single quotes those are used if you want punctuation in title or subject.)

This will cause OS X to relay the message to your ISP’s SMTP server, and send the message to the recipient that you specified.

If you get an Error like:

sendmail: fatal: chdir /Library/Server/Mail/Data/spool: No such file or directory


Then you have to do a little more work like this:

sudo mkdir -p /Library/Server/Mail/Data/spool sudo /usr/sbin/postfix set-permissions sudo /usr/sbin/postfix start


You didn’t get any mail still then now you will have to setup Google as your SMTP server?

Configure Postfix for Gmail SMTP
Edit file /etc/postfix/

sudo nano /etc/postfix/


relayhost = []:587 smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous smtp_use_tls = yes


Generate sasl_password if not already exists

sudo nano /etc/postfix/sasl_passwd


and enter in the following:

[]:587 [email protected]:password


Run the following commands

sudo chmod 600 /etc/postfix/sasl_passwd 
sudo postmap /etc/postfix/sasl_passwd 
sudo launchctl stop org.postfix.master 
sudo launchctl start org.postfix.master


I was trying to see if my port 25 was open so I used this command

(echo >/dev/tcp/localhost/25) &>/dev/null && echo "TCP port 25 opened" || echo "TCP port 25 closed"


A cool way to to see what ports are open with grep

sudo lsof -i -P | grep -i "listen"


Thats It enjoy what is built-in to your Mac!

edit: September 22, 2015

I forgot to tell you that you need to setup postfix to load automatically on boot so I added a file /System/Library/LaunchDaemons/org.postfix.master.plist file this file will load the postfix automatically.

so use nano to create a file with this command:

sudo nano /System/Library/LaunchDaemons/org.postfix.master.plist

copy the text below and paste into that file.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">

Now I think it is working even on reboot.

To use this with XTension it is pretty easy also. In your attachments folder create a Handler with text like this:

--eMail Script
on sendEmail(eSubject, eBody)
	set eRecipient to "[email protected]"
	write log "Email sent about:  " & eBody
		set theCommand to "echo " & eBody & " | mail -s " & quoted form of eSubject & " " & eRecipient

		do shell script theCommand
	on error msg number eNum
		write log "Sending Mail error:  " & eNum & " " & msg
	end try
end sendEmail

The results are that you are using the simple send like above 1 line with the echo of the Body and this one will take punctuation in the Subject and Body.