The UNIX-command line
After a while experimenting with the standard mail in terminal and the usage of SMTP and postfix, I decided not to use this method anymore and have installed
Please see my experiences on PHP Mail Local OSX and Web-Internet.
Send with Attachment
To send an email from UNIX/Linux with the attachment as filename. Use:
uuencode DbTables.txt TheDbTables.txt| mail -s "Title DbTables" email@example.com
- uuencode the file DbTables.txt and name in as attachment TheDbTables.txt.
- Give it the title Title DbTables.
- Send to email address firstname.lastname@example.org.
To send an email with attachment and body use:
cat body.txt;uuencoce file file.txt|mailx -s "Attachments" email@example.com
To send a short note to the person with the email address firstname.lastname@example.org. Here is an example of how I would do this:
$ mail email@example.com Subject: Hi This is just a short note to say hello. I don't have anything else right now. . Cc: $
The first line:
$ mail firstname.lastname@example.org
Unix responded with the line starting with Subject: after hitting the Enter key.
- Type the text Hi and hit the Enter key.
- Type the first sentence and hit the Enter key.
- Type the second sentence and hit the Enter key.
- When done with the email message, type a period (.) in the first column.
This period in the first column told the mail program to stop.
The mail program then prompted with Cc: to ask for anyone else's email address whom will get copies of this message. Since there are no more email addresses used, press Enter, which will end the mail session, and give the shell prompt back. Alternatively to stop the mail use ctrl-D.
Mail on Mac OS X Lion
I have been trying to get my command line mail working on my MacOS (Lion) today and I noticed that the normal postfix emails get treated as SPAM by Google and because I was sending emails to myself on my gmail account, that was an issue for me. So, I thought of using gmail as my outgoing SMTP server for this. Here are the steps I followed :
Configure Postfix for Gmail SMTP Edit file /etc/postfix/main.cf
- sudo vim /etc/postfix/main.cf
and add in the following below the commented out relayhosts :-
- relayhost = [smtp.gmail.com]:587
- smtp_sasl_auth_enable = yes
- smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
- smtp_sasl_security_options = no anonymous
- smtp_use_tls = yes
Generate sasl_password if not already exists
- sudo vim /etc/postfix/sasl_passwd
and enter in the following:-
- [smtp.gmail.com]:587 email@example.com: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
And you are done….
Now, you should be able to send emails from within the command line e.g. to send the contents of a directory as a tree to an email address
- tree /var/www/somefolder | mail -s "contents" firstname.lastname@example.org
Hope someone finds this useful!
To stop postfix completely 
- sudo /bin/launchctl unload -w /System/Library/LaunchDaemons/org.postfix.master.plist
- sudo /bin/launchctl load -w /System/Library/LaunchDaemons/org.postfix.master.plist
The normal procedure are:
- sudo postfix start|stop|reload
But the stop functionality will immediate start postfix again that's why the /bin/launchctl unload is needed.
- UNIX_Command_Reference, Command line reference.
- Unix_Find, Find and grep text and files.
- Wikipedia Mail
- Cyberciti.biz, Postfix Start-Stop-Restart
- PostFix.org, Main Site
- Steve Jenkins, GMail Certificates
- Postfix unavailable
- Configure PostFix
- Benjamin Rojas, Configuring Postfix to send mail on Mac.
- MacWorld, Hints - Send mail from Terminal using mail/sendmail .
- https://topicdesk.com/faqs/os-x-server-mail-services/how-do-i-completely-disable-postfix-and-cyrus Topic Desk], How do I completely stop Postfix and Cyrus.