Categories: CyberPanel

[Commands] Installation of Gmail SMTP Relay on CentOS 7 Server for CyberPanel

In this tutorial, We will be learning how to send emails from CyberPanel using Gmail SMTP relay. Here is a quick guide, make sure you follow each and every step.

Here is list of commands we will be using to setup SMTP Relay for PostFix
(CentOS 7) and will be able to send emails using CyberPanel.

Requirements

  1. CyberPanel Installed using CentOS.
  2. Postfix should be installed & running.
  3. You should receive mails in CyberPanel.
  4. You should know how to use Vi/Vim Editor in Linux, if not follow this guide for Vim Editor.

Pre-Installation Setup of Postfix

Use the below command to install PostFix Cyrus Sasl Plain Mailx (Optional if using CyberPanel with Postfix Installed).

yum install postfix cyrus-sasl-plain mailx

Use the below command to restart & enable Postfix if it isn’t enabled.

systemctl restart postfix
systemctl enable postfix

Getting Gmail SMTP & AppPassword (Important Step)

To get the AppPassword for Gmail SMTP follow the below steps:

  • Click AppPasswords, then it will ask you to verify yourself, do it by entering your password and then generate an AppPassword with any name. See the video below.
  • Now that we have AppPassword, we will use it in our SMTP Settings, here is a cheatsheet below, save this with yourself.
SMTP username: Your Gmail address.
SMTP password: Your Gmail AppPassword (Which we generated).
SMTP server address: smtp.gmail.com
Gmail SMTP port (TLS): 587 or 465 (You can test both).

Now that everything is ready, let’s get started with adding our Gmail SMTP Relay to the server, so that we can send email very very soon 😀

Are you looking to Install CyberPanel?

If you are looking to install CyberPanel take a quick look at CyberPanel Installation Youtube Tutorial.

Setting up the SMTP Relay with Gmail

First make sure you are using root. Typing the following commands to make sure you are a root user.

sudo su root
su - root
cd /
Make sure you use all the command listed above.

Now you have to edit the main.cf file using the below command and add few lines to it. Make sure you are in the “/” directory. Use the below command to add the text to main.cf file

vi /etc/postfix/main.cf

Copy the below lines, and paste them in main.cf

relayhost = [smtp.gmail.com]:465 or 587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous

Are you unable to use vi or vim? (Optional)

To edit files like main.cf you need a Vim Editor, if the above commands worked fine ignore this message but if you are facing errors use the below commands
sudo yum install vim
sudo yum update

Adding Password in Postfix for Gmail SMTP Relay

To add the password, we won’t be using Gmail Default Password. Instead we will use the App-password we generated above, if you didn’t get the App Password scroll up and follow the steps again.

If you have the App-Password already, follow the below command.

vim /etc/postfix/sasl_passwd

When you use the above command an editor will open, you have to paste lines of code mentioned below.

[smtp.gmail.com]:587 or 465 yourgmail@here.com:yourAppPassword

Note: Remove one of the port, make sure in the above step while adding lines of code to main.cf you are using same port number as in here.

For 465 Port Use this line:

[smtp.gmail.com]:465 yourgmail@here.com:yourAppPassword

For 587 Port Use this line:

[smtp.gmail.com]:587 yourgmail@here.com:yourAppPassword

Summing Up & Testing

Congrats! We are close to sending emails now. Use these below commands now:

postmap /etc/postfix/sasl_passwd
chown root:postfix /etc/postfix/sasl_passwd*
chmod 640 /etc/postfix/sasl_passwd*

We are done, that’s all. Now restart the Postfix using the below command:

systemctl reload postfix

Test out everything, if you face errors. Feel free to join CyberPanel Facebook Community and ask questions.

You can do me a huge favor by subscribing to my email list, I don’t send spam neither I send emails every single day. I will send emails when I launch a new CyberPanel Tutorial.

thesheryar

I'm a dedicated WordPress Web Developer, specializing in crafting seamless online experiences. With a keen eye for design and a knack for turning concepts into functional, user-friendly websites, I'm here to bring your digital vision to life. Let's create something amazing together!

Recent Posts

CyberPanel to CyberPanel Migrating to Another Server

In this tutorial, you will be learning how to properly transfer all your CyberPanel accounts…

1 year ago

What is Cryptocurrency? And Cryptocurrency in Pakistan

(Cryptocurrency’s work and drawbacks in Pakistan) I will not take your extra time to read…

4 years ago

What is BlockChain?

Hey Readers!Block Chain isn't some sort of complex thing to understand, it's really simple but…

4 years ago

What is Bitcoin? How to make Bitcoin account in Pakistan and India? Bitcoin Buy/Sell in Pakistan and India.

To finish your confusion about the bitcoin, I’ll explain bitcoin briefly and efficiently.What is bitcoin?…

4 years ago

This website uses cookies.