Sending Mails from your Ubuntu Server

July 2026

How can I send mails from the command line?

The first thing you'll need is a gmail account, that is dedicated to this purpose. So go ahead and create one. Google has removed the old "less secure apps" option, so you'll need an app password instead: turn on 2-Step Verification for the account, then create an app password at https://myaccount.google.com/apppasswords.

After having set up your Gmail Account for sending mails, you can log in to your server and run through the following steps.

  1. sudo apt-get install ssmtp mailutils
  2. Open the following file in your favorite text editor (vim, nano, ...):
    nano /etc/ssmtp/ssmtp.conf
  3. Append the following lines:
    root=username@gmail.com
    mailhub=smtp.gmail.com:465
    rewriteDomain=gmail.com
    AuthUser=username@gmail.com
    AuthPass=your-app-password
    FromLineOverride=YES
    UseTLS=YES
  4. Finally, send mails like this:
    echo "Hi there!" | mail -s "My Subject" recipient@example.com
Tax Wealth, Not Work
Wages get taxed to the bone while the ultra-rich watch their assets compound untouched — and then buy up the houses you're saving for. If you work for your money, this is your fight too.
Watch on YouTube →