UNIX mail
The UNIX-command line Mail
can do everything but it is a little bit nasty. Feel free to add more.
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 PHPMailer.php
.
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" frielink@xx.yyy.com
Explanation:
- uuencode the file DbTables.txt and name in as attachment TheDbTables.txt.
- Give it the title Title DbTables.
- Send to email address frielink@xx.yyy.com.
To send an email with attachment and body use:
cat body.txt;uuencoce file file.txt|mailx -s "Attachments" xyz@xxx.com
Mail Basics
To send a short note to the person with the email address nobody@december.com. Here is an example of how I would do this:
$ mail nobody@december.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 nobody@december.com
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 username@gmail.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" your@yourdomain.com
Hope someone finds this useful!
Postfix
To stop postfix completely [1]
- sudo /bin/launchctl unload -w /System/Library/LaunchDaemons/org.postfix.master.plist
To Relaunch
- 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.
See also
- UNIX_Command_Reference, Command line reference.
- Unix_Find, Find and grep text and files.
- Wikipedia Mail
Postfix tls
- Cyberciti.biz, Postfix Start-Stop-Restart
- PostFix.org, Main Site
- PostFix.org, Documentation
- PostFix.org, TLS-loglevel
- PostFix.org, Quick Start
- Steve Jenkins, GMail Certificates
- Postfix unavailable
- Configure PostFix
- Benjamin Rojas, Configuring Postfix to send mail on Mac.
MacOS
- MacWorld, Hints - Send mail from Terminal using mail/sendmail .
Postfix.de
References
- ↑ 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.