Related Items  

Linux and Windows IT Support  


Windows, Apple and Linux IT support and services.

For Software and Web Development.

Send email from a command line


gnome terminal

Q. I would like to send an email from a command line in bash, how do I do that?

A. Assuming you have your outgoing server configured and either bsd-mailx or mailx (simple mail user agent for Linux) you can use this command to send out email:

echo "Email body text" | mail -s "Email subject"

If you do not have your tools configured, you can send an email using telnet:

telnet localhost 25

The response should be:

Connected to localhost.
Escape character is '^]'.
220 ESMTP Postfix (Ubuntu)

Next, type in:


The response should be something like that:


Next, type in the from email address:

mail from:

And you should getting something like this from the server:

250 2.1.0 Ok

Type in the recipient:

rcpt to:

The response from the server will be along those lines:

250 2.1.5 Ok

To enter the email body, type in DATA. To finish your email body, type a dot on an empty line and press enter:


This is the response you'll get:

354 End data with <CR><LF>.<CR><LF>

Type in your email body:

Subject: test
Testing email.

Finally, if all goes well you'll get a response from the server, with something like this:

250 2.0.0 Ok: queued as 9470323291

There are many things that can go wrong while sending through telnet, such as required authentication, server misconfiguration, etc., so we assume that you have the server configured.


Add your comment

Your name:
  The word for verification. Lowercase letters only with no spaces.
Word verification:
yvComment v.1.24.0
Copyright © 1999 - 2022 Virtual Helpme | IT Services Catered to Your Business | Original Template: Allrounder