<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://lms.onnocenter.or.id/wiki/index.php?action=history&amp;feed=atom&amp;title=Linux%3A_mailx_command_%28en%29</id>
	<title>Linux: mailx command (en) - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://lms.onnocenter.or.id/wiki/index.php?action=history&amp;feed=atom&amp;title=Linux%3A_mailx_command_%28en%29"/>
	<link rel="alternate" type="text/html" href="https://lms.onnocenter.or.id/wiki/index.php?title=Linux:_mailx_command_(en)&amp;action=history"/>
	<updated>2026-04-20T09:17:52Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://lms.onnocenter.or.id/wiki/index.php?title=Linux:_mailx_command_(en)&amp;diff=71794&amp;oldid=prev</id>
		<title>Unknown user: Created page with &quot;Send emails from the command line  The mail command is essential and should be available on any Linux server so that various services and other web applications can generate a...&quot;</title>
		<link rel="alternate" type="text/html" href="https://lms.onnocenter.or.id/wiki/index.php?title=Linux:_mailx_command_(en)&amp;diff=71794&amp;oldid=prev"/>
		<updated>2025-01-06T23:28:03Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Send emails from the command line  The mail command is essential and should be available on any Linux server so that various services and other web applications can generate a...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Send emails from the command line&lt;br /&gt;
&lt;br /&gt;
The mail command is essential and should be available on any Linux server so that various services and other web applications can generate and transmit emails.&lt;br /&gt;
&lt;br /&gt;
In a previous post on the mail command, we saw how the mail command can be used to send emails from the command line on your Linux server.&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we will be using an enhanced version of the mail command called mailx (or just mail when installed), which can do many more things than the older mail command from the GNU mailutils package.&lt;br /&gt;
How it works&lt;br /&gt;
&lt;br /&gt;
The mail/mailx command requires a local SMTP server (MTA) running to deliver the emails. The email route is somewhat like this:&lt;br /&gt;
&lt;br /&gt;
 mail -&amp;gt; sendmail -&amp;gt; local MTA -&amp;gt; recipient MTA [Inbox]&lt;br /&gt;
&lt;br /&gt;
The recipient MTA would be Gmail&amp;#039;s SMTP server if your recipient is someone at gmail.com, for example. For the local MTA, you need to install an SMTP server like Postfix. A basic installation of Postfix with minimal configuration would work in most cases.&lt;br /&gt;
&lt;br /&gt;
==Install the mailx command==&lt;br /&gt;
&lt;br /&gt;
On Ubuntu/Debian based systems, the mailx command is available from two different packages:&lt;br /&gt;
&lt;br /&gt;
# heirloom-mailx&lt;br /&gt;
# bsd-mailx&lt;br /&gt;
&lt;br /&gt;
We shall be using the heirloom-mailx package because it has more features and options.&lt;br /&gt;
On CentOS/Fedora based systems, there is only one package named &amp;quot;mailx,&amp;quot; which is the heirloom package.&lt;br /&gt;
&lt;br /&gt;
To find out which mailx package is installed on your system, check the &amp;quot;man mailx&amp;quot; output and scroll down to the end, and you should see some useful information.&lt;br /&gt;
&lt;br /&gt;
 # ubuntu/debian&lt;br /&gt;
 $ sudo apt-get install heirloom-mailx&lt;br /&gt;
 &lt;br /&gt;
 # fedora/centos&lt;br /&gt;
 $ sudo yum install mailx&lt;br /&gt;
&lt;br /&gt;
==Using the mailx command==&lt;br /&gt;
&lt;br /&gt;
Once installed, the mailx command can be directly referenced with the name mail, so you just type that in the command line.&lt;br /&gt;
&lt;br /&gt;
==1. Simple mail==&lt;br /&gt;
&lt;br /&gt;
Run the following command, and then mailx would wait for you to enter the email message. You can hit enter for new lines. When done typing the message, press Ctrl+D, and mailx would display EOT. After that, mailx automatically delivers the email to the destination.&lt;br /&gt;
&lt;br /&gt;
 $ mail -s &amp;quot;This is the subject&amp;quot; someone@example.com&lt;br /&gt;
 Hi someone,&lt;br /&gt;
 How are you?&lt;br /&gt;
 I am fine.&lt;br /&gt;
 Bye&lt;br /&gt;
 EOT&lt;br /&gt;
&lt;br /&gt;
==2. Take message from a file==&lt;br /&gt;
&lt;br /&gt;
The message body of the email can also be taken from a file:&lt;br /&gt;
&lt;br /&gt;
 $ mail -s &amp;quot;This is the Subject&amp;quot; someone@example.com &amp;lt; /path/to/file&lt;br /&gt;
&lt;br /&gt;
The message can also be piped using the echo command:&lt;br /&gt;
&lt;br /&gt;
 $ echo &amp;quot;This is the message body&amp;quot; | mail -s &amp;quot;This is the Subject&amp;quot; someone@example.com&lt;br /&gt;
&lt;br /&gt;
==3. Multiple recipients==&lt;br /&gt;
&lt;br /&gt;
To send the mail to multiple recipients, specify all the emails separated by a comma:&lt;br /&gt;
&lt;br /&gt;
 $ echo &amp;quot;This is the message body&amp;quot; | mail -s &amp;quot;This is the Subject&amp;quot; &lt;br /&gt;
 someone@example.com,someone2@example.com&lt;br /&gt;
&lt;br /&gt;
==4. CC and BCC==&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;-c&amp;quot; and &amp;quot;-b&amp;quot; options can be used to add CC and BCC addresses respectively:&lt;br /&gt;
&lt;br /&gt;
 $ echo &amp;quot;This is the message body&amp;quot; | mail -s &amp;quot;This is the Subject&amp;quot; -c ccuser@example.com someone@example.com&lt;br /&gt;
&lt;br /&gt;
==5. Specify From name and address==&lt;br /&gt;
&lt;br /&gt;
To specify a &amp;quot;FROM&amp;quot; name and address, use the &amp;quot;-r&amp;quot; option. The name should be followed by the address wrapped in &amp;quot;&amp;lt;&amp;gt;&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ echo &amp;quot;This is the message body&amp;quot; | mail -s &amp;quot;This is the Subject&amp;quot; -r &lt;br /&gt;
 &amp;quot;Harry&amp;lt;harry@gmail.com&amp;gt;&amp;quot; someone@example.com&lt;br /&gt;
&lt;br /&gt;
==6. Specify &amp;quot;Reply-To&amp;quot; address==&lt;br /&gt;
&lt;br /&gt;
The reply-to address is set with the internal option variable &amp;quot;replyto&amp;quot; using the &amp;quot;-S&amp;quot; option:&lt;br /&gt;
&lt;br /&gt;
 $ echo &amp;quot;This is the message&amp;quot; | mail -s &amp;quot;Testing replyto&amp;quot; -S replyto=&amp;quot;mark@gmail.com&amp;quot; &lt;br /&gt;
 someone@example.com&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==7. Attachments==&lt;br /&gt;
&lt;br /&gt;
Attachments can be added with the &amp;quot;-a&amp;quot; option:&lt;br /&gt;
&lt;br /&gt;
 $ echo &amp;quot;This is the message body&amp;quot; | mail -s &amp;quot;This is the Subject&amp;quot; -r &lt;br /&gt;
 &amp;quot;Harry&amp;lt;harry@gmail.com&amp;gt;&amp;quot; -a /path/to/file someone@example.com&lt;br /&gt;
&lt;br /&gt;
==8. Use external SMTP server==&lt;br /&gt;
&lt;br /&gt;
This is an exclusive feature, available only with heirloom mailx and not with bsd mailx, the mail command from GNU mailutils, or the mutt command.&lt;br /&gt;
&lt;br /&gt;
The mailx command can use an external SMTP server to relay the message. The syntax is a bit lengthy but makes sense:&lt;br /&gt;
&lt;br /&gt;
 $ echo &amp;quot;This is the message&amp;quot; | mailx -v -r &amp;quot;someone@example.com&amp;quot; -s &amp;quot;This is the subject&amp;quot; -S smtp=mail.telkom.net onno@indo.net.id&lt;br /&gt;
&lt;br /&gt;
For Gmail specifically, you would need to enable less secure apps settings before you can send mail like this.&lt;br /&gt;
&lt;br /&gt;
==9. Verbose - watch SMTP communication==&lt;br /&gt;
&lt;br /&gt;
When using external SMTP servers, you can choose to watch the entire SMTP communication done in the background. This is useful especially when testing or debugging SMTP servers.&lt;br /&gt;
&lt;br /&gt;
 $ echo &amp;quot;This is the message body and contains the message from heirloom mailx&amp;quot; | mailx -v -s &amp;quot;This is the subject&amp;quot; -S smtp=&amp;quot;smtp.gmail.com:587&amp;quot; -S smtp-use-starttls -S smtp-auth=login -S smtp-auth-user=&amp;quot;mygmail@gmail.com&amp;quot; -S smtp-auth-password=&amp;quot;mypassword&amp;quot; -S ssl-verify=ignore someone@example.com&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [Binary Tides - Linux mailx command](http://www.binarytides.com/linux-mailx-command/)&lt;/div&gt;</summary>
		<author><name>Unknown user</name></author>
	</entry>
</feed>