How to Send Mail using Gmail Credentials on Ubuntu?

How to Send Mail using Gmail Credentials on Ubuntu?

In today's interconnected world, email communication is an indispensable part of our daily lives. Ubuntu, a popular Linux distribution, provides users with a powerful platform for various tasks, including sending emails. This guide will walk you through the process of sending emails using Gmail credentials on Ubuntu, combining the flexibility of Linux with the convenience of Gmail.

Setting up your Environment:

Before we delve into the steps, make sure you have a Gmail account and a working Ubuntu system. If you don't have the mailutils package installed, open a terminal and use the following command:

sudo apt-get install mailutils

Configuring Gmail Credentials:

To use Gmail for sending emails, you need to configure your Gmail credentials on your Ubuntu machine. This involves creating an "App Password" to ensure secure authentication.

  1. Go to your Google Account settings.
  2. Under "Security," select "App Passwords."
  3. Choose "Mail" as the app and "Other (Custom Name)" for the device.
  4. Click "Generate" to get the App Password.
  5. Save the generated App Password for later use.

Configuring Mailutils:

Now, let's configure mailutils to use your Gmail credentials.

nano ~/.mailrc

Add the following lines to the configuration file:

set smtp=smtps://
set smtp-auth=login
set smtp-auth-password=your-app-password

Replace "" with your Gmail address and "your-app-password" with the App Password generated earlier.

Sending an Email:

With the configuration in place, you can now send an email using the mail command:

echo "This is the body of the email" | mail -s "Subject of the Email"

Replace "This is the body of the email" with your message, "Subject of the Email" with your desired subject, and "" with the recipient's email address.

Additional Tips and Examples:

  • To send an email with a file attachment:
echo "Body of the email" | mail -s "Subject" -a /path/to/attachment.txt
  • To send an email with multiple recipients:
echo "Body of the email" | mail -s "Subject" -c -b

In this guide, we've covered the steps to configure Gmail credentials on Ubuntu and send emails using the mailutils package. Email communication on a Linux system doesn't have to be complicated, and with this setup, you can seamlessly integrate Gmail into your Ubuntu workflow.

Related Searches and Questions asked:

  • How to Install Linux on a Virtual Machine Easily?
  • Linux Commands Cheat Sheet
  • Best Text Editors for Linux
  • Top Linux Distributions for Beginners
  • That's it for this topic, Hope this article is useful. Thanks for Visiting us.