mailx
From Wikipedia, the free encyclopedia
mailx is a Unix utility program for sending and receiving mail, also known as a Mail 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 as procmail.
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.
[edit] 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 -r "me<email@mail.com>"
"person1<person1@hotmail.com>" "person2<person2@hotmail.com>" mensagem . EOT
Sends 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