Watch all our Tutorials and Training Videos for Free on our Youtube Channel, Get Online Web Tools for Free on swebtools.com

Search Suggest

How to Send Mail using Gmail Credentials on Ubuntu?

send mails from ubuntu, send mail using gmail from ubuntu, ubuntu send mail to gmail, ubuntu send email gmail, ubuntu send email using gmail account

 

How to Send Mail using Gmail Credentials on Ubuntu

Sending email on Ubuntu using Gmail credentials is a straightforward process that requires some initial setup. With the right configuration, you can use the command line to send emails from your Ubuntu machine using your Gmail account. Here's how to do it.

Step 1: Install the required packages

The first step is to install the packages needed for sending email on Ubuntu. Use 'apt-get' command directly to install as below.

sudo apt-get install msmtp msmtp-mta

This command will install the "msmtp" package, which is a simple command-line SMTP client, and the "msmtp-mta" package, which sets up MTA (Mail Transfer Agent) support for msmtp.

Step 2: Configure msmtp for Gmail

The next step is to configure msmtp to use your Gmail account for sending email. Open the msmtp configuration file by using any editor as you prefered, here we use 'vim':

sudo vim /etc/msmtprc

Add the below values into the opened file:

account default
host smtp.gmail.com
port 587
auth on
user your_email@gmail.com
password your_password
from your_email@gmail.com
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt

Replace "your_email" and "your_password" with your Gmail email address and password. Save and Exit from the file..

Step 3: Test the configuration

To test the configuration, run the following command in the terminal:

echo "Hello, World!" | msmtp recipient_email@gmail.com

Replace "recipient_email" with the email address of the person you want to send the email to.

This command will send a test email to the recipient using your Gmail account. If everything is working correctly, you should see a "queued for delivery" message.

Step 4: Set up an alias

To make sending emails even easier, you can set up an alias in your ".bashrc" file. You can use any editor as you are comfortable to edit like below. For this example, we use 'vim' editor.

vim ~/.bashrc

Add the following line to the file:

alias gmail='echo "Type your message. Press Ctrl-D when finished." && cat | msmtp recipient_email@gmail.com'

Replace "recipient_email" with the email address of the person you want to send the email to. Save and Exit from the file..

Step 5: Send an email using the alias

To send an email using the alias, run the following command in the terminal:

gmail

Above command will openup a file in your default editor, Type your message, and then press Ctrl-D when finished. The message will be sent to the recipient using your Gmail account.

That’s it for this post, Hope this post helped you to understand How to Send Mail using Gmail Credentials on Ubuntu.

Keep practicing and have fun. Leave your comments if any.

Support Us: Share with your friends and groups.

Stay connected with us on social networking sites, Thank you.