Unix Mail
The UNIX-command line Mail
can do everything but it is a little bit nasty. Feel free to add:
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!
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,