mailx is a Linux command line mail client. It is typically used to send mail from shell scripts. By default, mailx will use a local MTA (typically sendmail) to actually transfer emails to a mail server. If your machine does not have sendmail or any other MTAs, you will need to configure mailx to use an external mail server.

Usage[edit | edit source]

The email message is piped to mailx. Specify -s for subject. Any options are passed as variables set using -S key=value. Recipients are specified at the end.

For example, to send a test message using an external SMTP server:

$ echo "Hello there." | mail -s "test" -S smtp=smtp:// ""

Rather than specifying multiple values with multiple -S parameters, values can also be defined in /etc/mail.rc using set key=value. For example, to use an external mail server with SMTP authentication:

set smtp=smtp://
set smtp-auth=login
set smtp-auth-user=""
set smtp-auth-password="mein-passwort"
set smtp-use-starttls
set from="Home Robot <>"

To verify whether mail is being sent successfully, use -v for verbose outputs.

root@nas:~# echo "testing" | mail -v -s testing
Resolving host . . . done.
Connecting to . . . connected.
220 ESMTP ready
>>> EHLO nas
220 2.0.0 Start TLS
Comparing DNS name: ""
>>> EHLO nas
>>> Vh
>>> VU
235 2.0.0 OK
>>> MAIL FROM:<>
250 2.1.0 Ok
>>> RCPT TO:<>
250 2.1.5 Ok
>>> DATA
354 End data with <CR><LF>.<CR><LF>
>>> .
250 2.0.0 Ok: queued as 25661254B6
>>> QUIT
221 2.0.0 Bye