Sending Email from mailx Command in Linux Using Gmail’s SMTP introduces how to send email using mailx or mail command in Linux through Gmail’s SMTP which requires some configuration. On the other hand, there are many environments that do not require SSL/TLS/etc. One example is the SMTP server ( for HKUST requires no authentication for sending email from IPs inside the campus network. In this tutorial, I will introduce how to send email using mailx through internal SMTP (using HKUST’s smtp server as the example).

There are at least two methods: using all-in-one command or putting configurations into profile. The all-in-one-command way needs no other configurations except the command line itself, while the way using configuration has a clearer command.


All-in-one command

This is an all-in-one command that sends email to $TO_EMAIL_ADDRESS . You need to also replace these $FROM_EMAIL_ADDRESS and $FRIENDLY_NAME variables with your email and name.

$ mailx -v -s "$EMAIL_SUBJECT" \
-S smtp=smtp:// \

mailx will read the email content from STDIN. Type in the email main content and input “Ctrl+d” to tell mailx you have finished the content. The mail will be sent out. You can also use pipes like:

$ echo "The mail content" | mail -v -s ...

Using configuration file

If you use this configuration frequently, you man consider putting the configuration into mailx‘s configuration file ~/.mailrc.

set smtp=smtp://

Then you can send email directly by:


Eric Zhiqiang Ma

Eric Zhiqiang Ma is interested in operating systems and distributed computing and processing systems. Find Eric on Facebook, Twitter, LinkedIn and Google+. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *