March 7, 2026

PBX Science

VoIP & PBX, Networking, DIY, Computers.

Gmail: How to send email from linux server?

Gmail: How to send email from linux server?



Gmail: How to send email from linux server?

Gmail: How to send email from linux server?  Gmail is the first email choice for personal uses.

Very convenient, easy to use, but you have to do some configuration if gmail is used to send system notice from your linux server.

01 Turn on less security in Gmail

  1. Login in your Gmail account from web browser
  2. Click Google Apps and select “Account”
  3. Click “Security”
  4. Find “Less secure app access”
  5. Turn on it

Gmail: How to send email from  linux server?

02 Configuration

CentOS:

Login in with root via SSH

  • Install POSTFIX and mailx

yum install postfix

systemctl restart postfix

yum install cyrus-sasl cyrus-sasl-lib cyrus-sasl-plain

yum install mailx

  • Edit main.cf

nano /etc/postfix/main.cf

  • Add blow lines to the end of main.cf

#postfix send email via gmail on Aug 09 2020

relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_use_tls = yes

  • Create the file /etc/postfix/sasl_passwd with the following contents:

nano /etc/postfix/sasl_passwd

  • Add your Gmail information

[smtp.gmail.com]:587 user.name@gmail.com:password

  • Restrict permissions on the postfix file:

chmod 400 /etc/postfix/sasl_passwd

chown root.root /etc/postfix/sasl_passwd

  • Hash the file into a .db that Postfix will read:

postmap /etc/postfix/sasl_passwd

  • Change the owner of the sasl_passwd to the postfix user:

chown postfix /etc/postfix/sasl_passwd

  • Reload postfix:

service postfix restart

  • Test email

echo "Test mail from postfix" | mail -s "Test Postfix" youremail@gmail.com

Debian or Ubuntu Server:

The process is almost same as CentOS, the only difference is to install mailutils instead of mailx.

sudo apt install mailutils

 


Ubuntu Server:

To send email via a Gmail account from an Ubuntu Linux server, you can follow these steps:

  1. Install the ssmtp package on your Ubuntu Linux server using the following command:
sudo apt-get update
sudo apt-get install ssmtp
  1. Once the package is installed, open the SSMTP configuration file using a text editor:
sudo nano /etc/ssmtp/ssmtp.conf
  1. Modify the configuration file with the following settings:
root=<your-email-address>
mailhub=smtp.gmail.com:587
rewriteDomain=gmail.com
hostname=<your-hostname>
UseSTARTTLS=YES
AuthUser=<your-gmail-username>
AuthPass=<your-gmail-password>
FromLineOverride=YES

Replace <your-email-address>, <your-hostname>, <your-gmail-username>, and <your-gmail-password> with your own values.

  1. Save the file and exit the text editor.

  2. Test the email configuration by sending a test email using the following command:

echo "This is a test email" | sudo ssmtp <recipient-email-address>

Replace <recipient-email-address> with the email address of the recipient you want to send the email to.

  1. If the test email is sent successfully, you can use the ssmtp command to send email from your Ubuntu Linux server using your Gmail account.

Note: Google may block sign-in attempts from some apps or devices that do not use modern security standards.

If you encounter issues, you may need to adjust the security settings of your Google account to allow access from less secure apps.

 
 
 

 


Debian Linux server

 
To send email via a Gmail account from a Debian Linux server, you can follow these steps:
  1. Install the ssmtp package on your Debian Linux server using the following command:
 
sudo apt-get update
sudo apt-get install ssmtp
  1. Once the package is installed, open the SSMTP configuration file using a text editor:
 
sudo nano /etc/ssmtp/ssmtp.conf
  1. Modify the configuration file with the following settings:
 
root=<your-email-address>
mailhub=smtp.gmail.com:587
rewriteDomain=gmail.com
hostname=<your-hostname>
UseSTARTTLS=YES
AuthUser=<your-gmail-username>
AuthPass=<your-gmail-password>
FromLineOverride=YES

Replace <your-email-address>, <your-hostname>, <your-gmail-username>, and <your-gmail-password> with your own values.

  1. Save the file and exit the text editor.

  2. Test the email configuration by sending a test email using the following command:

 
echo "This is a test email" | sudo ssmtp <recipient-email-address>

Replace <recipient-email-address> with the email address of the recipient you want to send the email to.

  1. If the test email is sent successfully, you can use the ssmtp command to send email from your Debian Linux server using your Gmail account.

Note: Google may block sign-in attempts from some apps or devices that do not use modern security standards.

If you encounter issues, you may need to adjust the security settings of your Google account to allow access from less secure apps.


Free IP PBX solutions:

How to Build an Enterprise-class Phone System?
How to Build IP-PBX on Raspberry Pi?
PBXscience.com © All Copyrights Reserved. | Newsphere by AF themes.