The Smartest Ways to Send Email from the Linux Command Line


Even despite the fact that part a century has handed because the first electronic mail message was once despatched, we nonetheless depend on historical generation day-to-day. Modern electronic mail purchasers and products and services are graceful, simple to make use of, and filled with extra complex options than maximum customers know the way to make use of.

Sometimes, on the other hand, all you wish to have to do is ship a easy text-only message, and also you would possibly not at all times be capable to release a GUI utility or log in to a webmail interface to get the task finished. In such scenarios, it’s at hand to know the way to ship electronic mail from the Linux command line, and this newsletter explains the right way to just do that.

Before We Begin

Before we describe the neatest techniques to ship electronic mail from the Linux command line, what you’ll be able to be expecting to be informed by way of studying this newsletter:

You will be informed to ship electronic mail messages via your electronic mail supplier’s SMTP server to any electronic mail deal with.

You gained’t be informed the right way to arrange your electronic mail server and use it to ship electronic mail messages immediately.

Why now not? Because no person would settle for emails despatched out of your electronic mail server anyway. As you realize, junk mail is a big downside in relation to electronic mail, and nearly all electronic mail provider suppliers and mail servers now come with a minimum of fundamental junk mail coverage that reasons all emails from doubtful assets to be rejected.

An avid Linux consumer with a DIY electronic mail server is regarded as a doubtful supply of electronic mail. What’s extra, maximum web provider suppliers block port 25, which is the usual port used for SMTP connections, so you probably wouldn’t even be capable to ship messages within the first position.

Instead of going via all of the hassle of creating a house electronic mail server paintings, it’s a lot more uncomplicated to make use of an electronic mail provider like Gmail, which we’ll be the use of for this newsletter.

If you haven’t finished so already, log in for your Gmail account and allow IMAP get right of entry to from the Forwarding and POP/IMAP tab in Settings. You must additionally permit apps that use much less protected sign-in generation.

Method #1: Mutt

Mutt is a venerable electronic mail Jstomer. It was once created in 1995 by way of Michael Elkins, and it’s been receiving updates at a gradual fee ever since. Despite its command-line nature, Mutt helps many helpful options, together with keyboard macros, PGP/MIME, message threading, attachments, and a lot more. You can use it with any electronic mail provider that gives POP3 or IMAP get right of entry to.

First, you wish to have to put in Mutt out of your distribution’s repositories:

Then you’ll be able to release Mutt:

You might be requested to create a Mail listing. Choose “yes” to create it. Mutt must release and let you know that no mailbox is open. Now that you just’ve showed that Mutt is operating, it’s time to create some fundamental directories and the principle configuration document, known as muttrc.

$ mkdir -p ~/.mutt/cache/headers

$ mkdir ~/.mutt/cache/our bodies

$ contact ~/.mutt/certificate

$ contact ~/.mutt/muttrc

Now, open the configuration document on your favourite textual content editor and duplicate & paste the next configuration (be sure you alternate the default settings to those who fit your Gmail electronic mail account):


set smtp_url = “smtp://[email protected]:587/”

set smtp_pass = $imap_pass

set ssl_force_tls = sure


set imap_user =

set imap_pass = password

set spoolfile = imaps://

set folder = imaps://

set report=“imaps://[Gmail]/Sent Mail”

set postponed=“imaps://[Gmail]/Drafts”

set mbox=“imaps://[Gmail]/All Mail”

set header_cache = “~/.mutt/cache/headers”

set message_cachedir = “~/.mutt/cache/bodies”

set certificate_file = “~/.mutt/certificates”


set editor = “nano”

You can now release Mutt, and it must robotically fetch your emails for you. To ship your first electronic mail message from the command line, press “m” for your keyboard. Choose to not recall a postponed message and input the recipient’s electronic mail deal with, the topic of the e-mail message, and, in any case, the frame of the message.

Before Mutt sends the e-mail message, it is going to help you alter it and fasten a document. Once you’re pleased with it, you’ll be able to press “y” to ship it. That’s how simple it’s to ship an electronic mail from the Linux command line!

Method #2: aerc

It more than likely gained’t wonder you to be informed that Mutt isn’t the one command-line electronic mail Jstomer for Linux, even if it’s indubitably the preferred one. While it will be past the scope of this newsletter to explain all command-line electronic mail purchasers for Linux, there are two extra purchasers we wish you to learn about, beginning with aerc.

Designed to be environment friendly and extensible, aerc brings to the desk make stronger for a couple of accounts, Vim-style keybindings, an interactive terminal internet browser able to rendering HTML emails, and extra.

Best of all, aerc is significantly more uncomplicated to arrange than Mutt, however there’s an opportunity that it gained’t be incorporated on your distribution’s repositories. In that case, you’ll be able to bring together it your self by way of following the directions at the professional directions.

When you will have aerc put in for your gadget, you’ll be able to release it the use of the “aerc” command. Aerc features a at hand setup wizard that can assist you configure your account—no wish to edit configuration information manually!

Once you’re finished coming into fundamental account knowledge and configuring a few fundamental settings, you’ll be able to both learn the bundled educational or move directly for your inbox.

To compose a brand new message, all you wish to have to do is press Shift + C.

Method #3: swaks

To ship electronic mail from the Linux command line the neatest method imaginable, you wish to have to assume out of doors the field and use device gear in techniques they weren’t supposed for use. The swaks utility is an all-purpose SMTP transaction tester that can be utilized to ship electronic mail messages via Gmail and different suppliers.

Start by way of putting in it similar to you might some other utility:

$ sudo apt set up a identification=“post-120921-_Hlk81403808”>a>swaks

Now, input the next command (be sure you come with your personal Gmail deal with) to check your connection:

$ swaks -t -s -tls -a LOGIN [enter]

You might be requested to go into your Gmail username (your electronic mail deal with) and your password. You must obtain an electronic mail deal with from your self, confirming that the take a look at was once a success. To ship a real electronic mail message, use the next syntax:

$ swaks –to -s -tls -au user-account> -ap account-password> –attach -d ./mail.txt

That’s how you’ll be able to ship an electronic mail message the use of swaks with a unmarried terminal command.

Method #4: sSMTP

sSMTP is an electronic mail supply program supposed to ship mail from a pc to a mail hub (SMTP server). This signifies that you’ll be able to use it to ship an electronic mail message to anyone else, however you’ll be able to’t use it to obtain an electronic mail message despatched to you by way of anyone else.

You can set up sSMTP by way of putting in the corresponding bundle from repositories:

Configuration is finished by way of modifying the /and so forth/ssmtp/ssmtp.conf configuration document:

# The consumer that will get all of the mails (UID

# The mail server (the place the mail is shipped to), each port 465 or 587 must be applicable

# See additionally https://make

# The deal with the place the mail seems to return from for consumer authentication.

# The complete hostname. Must be accurately shaped, totally certified area title or Gmail will reject the relationship.


# Use SSL/TLS earlier than beginning negotiation

TLS_CA_FILE=/and so forth/ssl/certs/ca-certificates.crt



# Username/Password




# Email ‘From header’s can override the default area?


To ship an electronic mail message, you wish to have to put in the mailutils (Debian-based programs) or mailx (RHEL-based programs) bundle to make use of the mail command to move your electronic mail message to sSMTP that it could actually ship it to Gmail. Like this:

$ echo -e “Subject: this is the subjectnnthis is the body” | mail

Method #5: Telnet

The ultimate way we wish to take a look at is the geekiest one of all of them, however it would come in useful sooner or later on your lifestyles, so a minimum of being acutely aware of its life is good. This way is dependent upon Telnet, a client-server protocol used to determine a far flung text-only connection over a community.

What’s nice about this technique is {that a} Telnet Jstomer is possibly already put in for your Linux distribution. What’s now not so nice is that there are lots of steps to move via. Since we’re the use of Gmail for the needs of this newsletter, you wish to have to make certain that your telnet Jstomer helps SSL encryption:

$ sudo apt set up telnet-ssl

You can then release your Telnet Jstomer and fasten it to Gmail’s SMTP server:

$ telnet -z ssl 465

Since it will be rude to not introduce ourselves, you’ll be able to greet the server like this:

If you’ve won a favorable reaction, you’ll be able to continue with authentication:

First, input your username encoded in base64 after which input your password, additionally encoded in base64. The SMTP server must reply with “334 UGFzc3dvcmQ6” each and every time.

Now it’s time to specify your electronic mail deal with:

MAIL FROM: electronic>

Then, specify the recipient:


Finally, inform the SMTP server that you need to jot down an electronic mail:

You can now input the topic of your electronic mail and press input to substantiate. Proceed with the frame of the mail and press input to substantiate. To shut your electronic mail message, input:


You must see a affirmation message that appears like this: 250 2.0.0 OK 1630506266 n10sm56478ejk.86 – gsmtp

Enter the next command to terminate your connection and ship the e-mail:


Is sending electronic mail messages from the Linux command line impractical? Perhaps, however you by no means know when this ability might be helpful. Even in case you by no means put it to just right use, a minimum of you’ll be able to be ok with your self, realizing that you just’ve turn into somewhat extra complex as a Linux consumer.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More