Sending Email With Gmail and Custom From Address Using GNU Mail
In this guide, we will walk you through the process of sending an email using Gmail as the SMTP server and customizing the “From” address using the GNU Mail command-line utility on a Ubuntu-based system. This can be useful if you want to send emails from a specific address other than your Gmail account.
Prerequisites
Before you begin, make sure you have the following prerequisites:
- A Ubuntu-based Linux system.
- A Gmail account from which you want to send emails.
- Internet connectivity.
Step 1: Install Required Packages
Open a terminal and install the necessary packages:
|
|
Step 2: Configure ssmtp
Edit the ssmtp configuration file to use your Gmail account for sending emails. You can use the text editor of your choice. In this example, we’ll use vim
:
|
|
Uncomment the following line to enable overriding the “From” address:
|
|
Add the following lines to configure Gmail as the SMTP server:
|
|
Make sure to replace [email protected]
and YOURPASSWORD
with your actual Gmail email address and password.
Save and exit the configuration file.
Step 3: Configure .mailrc
Install the bsd-mailx
package to enable GNU Mail to read the .mailrc
configuration file:
|
|
Create or edit the .mailrc
file in your home directory to set the default “From” address for outgoing emails. In this example, we’re setting it to “No Reply [email protected]”:
|
|
Step 4: Test Sending an Email
You can now test sending an email using the mail
command. Here are a couple of examples:
|
|
In this example, replace [email protected]
with the recipient’s email address.
|
|
This command sends an email with the custom “From” address specified in the .mailrc
file.
That’s it! You’ve successfully configured and tested sending emails using Gmail as the SMTP server and customizing the “From” address using GNU Mail on your Ubuntu-based system. You can now use these steps to send emails from your desired address using the mail
command.