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://mail.steamr.com:25 "recipient@steamr.com"

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://mail.steamr.com:587
set smtp-auth=login
set smtp-auth-user="home@steamr.com"
set smtp-auth-password="mein-passwort"
set smtp-use-starttls
set from="Home Robot <home@steamr.com>"

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

root@nas:~# echo "testing" | mail -v -s testing xyz@xyz.xyz
Resolving host mail.steamr.com . . . done.
Connecting to 107.189.11.145:587 . . . connected.
220 mail.steamr.com ESMTP ready
>>> EHLO nas
250-mail.steamr.com
250 STARTTLS
>>> STARTTLS
220 2.0.0 Start TLS
Comparing DNS name: "mail.steamr.com"
>>> EHLO nas
250-mail.steamr.com
250 AUTH PLAIN
>>> AUTH LOGIN
334 
>>> Vh
334 
>>> VU
235 2.0.0 OK
>>> MAIL FROM:<xyz@xyz.xyz>
250 2.1.0 Ok
>>> RCPT TO:<xyz@xyz.xyz>
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