Unix Mail

From HaFrWiki42
Jump to navigation Jump to search

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:

  1. uuencode the file DbTables.txt and name in as attachment TheDbTables.txt.
  2. Give it the title Title DbTables.
  3. 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

  1. sudo vim /etc/postfix/main.cf

and add in the following below the commented out relayhosts :-

  1. relayhost = [smtp.gmail.com]:587
  2. smtp_sasl_auth_enable = yes
  3. smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
  4. smtp_sasl_security_options = no anonymous
  5. smtp_use_tls = yes

Generate sasl_password if not already exists

  1. sudo vim /etc/postfix/sasl_passwd

and enter in the following:-

  1. [smtp.gmail.com]:587 username@gmail.com:password

Run the following commands

  1. sudo chmod 600 /etc/postfix/sasl_passwd
  2. sudo postmap /etc/postfix/sasl_passwd
  3. sudo launchctl stop org.postfix.master
  4. 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

  1. tree /var/www/somefolder | mail -s "contents" your@yourdomain.com

Hope someone finds this useful!

See also

top

Postfix tls

References

top