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.
- CyberPanel Installed using CentOS.
- Postfix should be installed & running.
- You should receive mails in CyberPanel.
- 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:
- Login to your Gmail Account.
- Go to the Gmail Security Settings.
- 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 /
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
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 AppPassword scroll up and follow the steps again or click here.
If you have the App-Password already, follow the below command.
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 email@example.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:
For 587 Port Use this line:
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.