- Mailx
mailx is a
Unix utility program for sending and receiving mail, also known as aMail User Agent program. It is an improved version of the mail utility.mailx is a lightweight mail program which has a command syntax similar to ed. Mailx allows one to send and read
email . Mailx cannot, by itself, receive email from another computer. It reads messages from a file on the local machine, which are delivered there by a local delivery agent such asprocmail .A simplified syntax with the most commonly used options is:
mailx [-s subject] [-a attachment ] [-r from-addr] to-addr . . .- -s subject of email (could be inserted later)
- -r indicates the email's sender (not a standard argument)
- -a file to be attached to email (in some versions)
- -a specify additional header fields (in other versions)
The end of message is indicated by a single '.' or by hitting ctrl+d.In the simple send usage, you just type your message directly into mailx. But in real life, you'll decide to edit the message after you've been typing for a while. Mailx interprets input lines beginning with a tilde (~) as commands. Its ~v command causes mailx to invoke the text editor of your choice (defined by the VISUAL environment variable) on the message in progress, saved in a temporary file. It can be argued this feature makes Mailx a more powerful email composing tool than typical Graphical User Interface (
GUI ) Mail User Agents.Example usage
A simple example prompt:mailx -s "From mailx" abc@cde.com
type the body ... EOT (i.e. Ctrl+d, then enter, to end).Simple syntax to send email with subject 'From mailx' to abc@cde.com.
A more complex example mailx -s "the subject" -a arq1 -a arq2 -a "From:me
"
"person1" "person2 " mensagem . EOTSends message to person1 and person 2 with arq1 and arq2 as anex. The subject of message will be "the subject" and the receivers will see "me" as the sender. Process the Variable in the Body of Mail example mailx -s "Subject" "dhil@yahoo.com" <<-EOT hi Dream, `date` this is the date on unix now EOT
In the above Example it will send the mail with the current date processed as follows. This is actually an example of a unix shell feature called a "here document." The mailx command has no idea where the text is coming from, it's just reading lines from its standard input. The stuff from the double less-than through the second EOT is interpreted by the shell, which runs the date command and inserts its output in the appropriate place. hi Dream, Thu Aug 23 02:25:38 EDT 2007 this is the date on unix now
One line example as a reminder for job completion
Suppose you have a job which it is going to run for a while. You don't want to stare at the screen to wait for its completion. You can switch to other terminal to work on other things but want to get notified the minute the job is completed. Here's the trick to do so:
sleep 24 && echo | mailx -s "XXX job completed" xxxxx@gmail.com
here "sleep 24" is just an example test run command to count for 24 seconds before the mailx command is executed. You should replace it with the job submission command of your choice. Once the job is completed, a mail with title "XXX job completed" and empty body will be sent to your gmail account. With gmail notifier, you will get notified the minute you receive the email and get to know that your job is completed. Of course, you can choose other email account and reminder method.
External references
[http://www.manpagez.com/man/1/mail/ Complete user's manual]
Wikimedia Foundation. 2010.