Send email through terminal — Ubuntu

I was setting up ubuntu on my new work laptop. Since our organization uses RSA keys for encryption, I created them using the ssh-keygen command. The next step was to add the public to the list of authorized keys of the remote machine hosted on AWS servers. Since I do not have access, I needed to email it to my CTO.

Now, One easy way would be to open the key in a text editor like VIM, copy and paste it in the email client and send. But that is not how you learn. So, I started exploring if there is a way to send the key through terminal itself. And there is!

The really simple way is this —

  1. install mailutils from ubuntu repositories — sudo apt-get install mailutils
  2. You are done. You can send mails using simple command — echo “This is a test email” | mail -s “TEST” <someone@gmail.com>

The above is a really simple way to send emails from terminal. However, since these emails are sent from an email address of the form <username@machine_name> ,these email would land up in SPAM, most if not all of the times (this might depend on your spam settings and your email provider). And that defeats the purpose. But worry not, we have options!

You can setup mail to send email from your regular email using this straightforward tutorial.

In case you use 2-factor authentication for you email account, you would need to generate app password for the account and replace the ‘AuthPass’ field in above tutorial with the app password. For gmail accounts, the app password can be set through this link.

For more ways to use mail command, you can check out this or simply google it.

Hope this was helpful!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.