How to Use Plesk on a VPS: Setting Up a Mail Server
Plesk is a powerful platform for managing VPS, offering a wide range of features, from website hosting to email management. In this article, we will focus on a specific task: setting up a mail server on your VPS using Plesk. We will break down the key steps, from installing the necessary components to configuring DNS records and troubleshooting common problems. This guide will provide you with practical examples and step-by-step instructions so you can successfully set up and manage a mail server on your VPS with Plesk.
Contents:
- Preparing Your VPS for Mail Server Installation
- Installing and Configuring the Mail Server in Plesk
- Configuring DNS Records for the Mail Server
- Enabling Spam and Virus Protection
- Diagnosing and Troubleshooting Common Problems
Preparing Your VPS for Mail Server Installation
Before proceeding with the installation and configuration of the mail server, it is necessary to ensure that your VPS meets the minimum requirements and is properly prepared. Improper preparation can lead to problems with the performance, security, and stability of the mail server.
Updating the Operating System
The first step is to update the VPS operating system to the latest stable version. This will ensure that you have the latest security patches and performance improvements.
# For Debian/Ubuntu
sudo apt update
sudo apt upgrade
# For CentOS/RHEL
sudo yum update
These commands will update all installed packages on your system, including the operating system kernel and system libraries. It is recommended to reboot the VPS after the update to ensure that all changes take effect:
sudo reboot
Checking System Requirements
Make sure your VPS has enough resources to run the mail server. Minimum requirements depend on the expected load, but it is recommended to have at least 2 GB of RAM and 20 GB of disk space. For more intensive use, consider increasing these parameters.
To check the amount of available RAM, use the command:
free -m
This command will show the total amount of RAM, used and free memory in megabytes.
To check available disk space, use the command:
df -h
This command will show disk space usage for all connected file systems. Pay attention to the «Avail» column to see the available space.
Setting the Hostname
A properly configured hostname is crucial for the correct operation of the mail server. Make sure the hostname of your VPS matches the domain name you plan to use for mail.
To check the current hostname, use the command:
hostname
To change the hostname, use the command:
sudo hostnamectl set-hostname mail.example.com
Replace «mail.example.com» with the actual domain name you plan to use for the mail server. Also, make sure the `/etc/hosts` file correctly specifies the relationship between the IP address and the hostname.
sudo nano /etc/hosts
Add or modify the line to match your IP address and hostname:
127.0.0.1 localhost
YOUR_VPS_IP mail.example.com mail
Expert Tip: Regularly update the operating system and monitor the use of VPS resources to ensure stable and secure operation of the mail server. Ignoring these steps can lead to vulnerabilities and performance issues.
Installing and Configuring the Mail Server in Plesk
Plesk simplifies the installation and configuration of a mail server with its built-in management interface. This section will guide you through the process of installing the mail server (usually Postfix or Courier IMAP) and basic settings.
Installing the Mail Server Component
By default, when installing Plesk, the mail server is not always installed. Make sure the Mail Server component is installed. To do this:
- Log in to Plesk with administrator rights.
- Go to «Tools & Settings».
- Select «Updates and Upgrades».
- Go to the «Add/Remove Components» tab.
- Expand the «Mail server» section and make sure the desired mail server (e.g., Postfix) is selected.
- Click «Continue» to install or remove the component.
After installing the component, Plesk will automatically configure the basic mail server configuration. However, for optimal operation, additional configuration will be required.
Basic Mail Server Configuration
Go to «Tools & Settings» -> «Mail Server Settings». Here you can configure the following parameters:
- Enable mail server: Check the box to activate the mail server.
- Domain name for mail sending: Specify the domain name that will be used for outgoing mail (usually the same as the hostname).
- Mail server operating mode: Choose one of the modes: «Open relay» (not recommended), «With authorization» (recommended) or «Closed». «With authorization» requires user authentication when sending mail, which prevents your server from being used for spamming.
- Maximum message size: Specify the maximum size of incoming and outgoing messages. Set a reasonable value to prevent server overload. For example, 25MB.
Example: Let’s say your domain is example.com and the hostname is mail.example.com. In the «Domain name for mail sending» field, specify mail.example.com. Select «With authorization» mode for security.
Configuring Relay SMTP
If your VPS has problems sending mail directly (for example, due to IP address blocking by the provider), you can configure Relay SMTP to send mail through a third-party service.
- In Plesk, go to «Tools & Settings» -> «Mail Server» -> «Relay SMTP Settings».
- Select «Use the SMTP relay server».
- Specify the hostname (or IP address) of the SMTP server, the port (usually 587 or 465), and the credentials (username and password) for authentication.
Example: If you are using SendGrid, specify smtp.sendgrid.net as the SMTP hostname, port 587, and your SendGrid credentials.
Creating Mailboxes
After setting up the mail server, you can create mailboxes for your domains.
- Go to the «Mail» section in Plesk.
- Select the domain for which you want to create a mailbox.
- Click «Create Email Address».
- Specify the mailbox name (e.g., info), password, and other parameters, such as disk space quota.
Example: For the domain example.com, you can create a mailbox info@example.com with the password «StrongPassword123» and a quota of 1 GB.
Practical Tip: Use strong passwords for all mailboxes and change them regularly. Enable two-factor authentication (if available) to improve account security.
Configuring DNS Records for the Mail Server
Proper configuration of DNS records is crucial for reliable email delivery. Incorrect DNS records can cause your emails to end up in spam or not be delivered at all. In this section, we will look at the main DNS records required for a mail server and show how to configure them.
A-Record (Address Record)
An A-record associates a domain name (or subdomain) with an IP address. For a mail server, you will need an A-record for your mail domain (for example, mail.example.com) pointing to the IP address of your VPS.
Example:
Name | Type | Value |
---|---|---|
mail.example.com | A | YOUR_VPS_IP |
Replace YOUR_VPS_IP with the actual IP address of your VPS. In Plesk, you can manage DNS records in «Websites & Domains» -> «DNS Settings» for the selected domain.
MX-Record (Mail Exchange Record)
The MX record specifies the mail server responsible for receiving mail for your domain. You must specify the priority of the MX record, which determines the order in which mail servers will try to deliver mail. A smaller number means higher priority.
Example:
Name | Type | Value | Priority |
---|---|---|---|
example.com | MX | mail.example.com | 10 |
This indicates that the mail.example.com mail server is responsible for receiving mail for the example.com domain. Priority 10 indicates that this is the primary mail server.
TXT-Records (Text Records): SPF and DKIM
TXT records are used to store text information associated with your domain. For a mail server, the most important are SPF (Sender Policy Framework) and DKIM (DomainKeys Identified Mail) records, which help prevent spoofing and increase trust in your mail.
SPF-record: specifies which mail servers are authorized to send mail on behalf of your domain.
Example:
v=spf1 a mx ip4:YOUR_VPS_IP -all
This SPF record allows sending mail from servers specified in the A-record and MX-record of the domain, as well as from the specified IP address (YOUR_VPS_IP). -all
means that all other servers are not authorized to send mail on behalf of your domain.
DKIM-record: uses a cryptographic signature to verify the authenticity of outgoing emails. Plesk can automatically generate DKIM keys and add the corresponding TXT record.
- In Plesk, go to «Mail» -> «Mail Settings» for the selected domain.
- Enable DKIM signature for outgoing mail.
- Plesk will automatically generate a DKIM key and add a TXT record to DNS.
Example DKIM TXT record: (the value will be generated by Plesk)
default._domainkey.example.com. TXT v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...
Important: After adding or changing DNS records, it may take some time (up to 48 hours) for the changes to propagate across the Internet. Use online tools such as MXToolbox (mxtoolbox.com) to verify that the DNS records are configured correctly.
Practical Tip: Regularly check your DNS records, especially after changing the server configuration or moving to another VPS. Incorrect DNS records are one of the most common causes of mail delivery problems.
Enabling Spam and Virus Protection
Spam and virus protection is an integral part of the reliable operation of a mail server. Plesk offers built-in tools for filtering spam and checking incoming and outgoing messages for malicious code. In this section, we will look at how to enable and configure these tools.
Enabling SpamAssassin
SpamAssassin is a popular open-source spam filter that analyzes the content of emails and assigns them scores based on the likelihood that it is spam. Plesk is integrated with SpamAssassin and makes it easy to enable and configure.
- In Plesk, go to «Tools & Settings» -> «Mail Server» -> «Spam Filter».
- Select «Switch on server-wide SpamAssassin spam filter».
- Configure the filter sensitivity. The lower the value, the more aggressive the filter will be. It is recommended to start with a medium value and adjust it to your needs.
- Specify the actions to take with detected spam. You can delete spam, move it to a special folder, or mark it in the subject of the email.
Example: Set the filter sensitivity to 5. Select «Move spam to the Spam folder» for easy viewing and deletion of spam.
You can also configure blacklists and whitelists for SpamAssassin to block or allow mail from certain addresses or domains.
Enabling Dr.Web Antivirus
Dr.Web Antivirus is a powerful antivirus that can scan incoming and outgoing emails for viruses and other malware. Plesk supports integration with Dr.Web if you have the appropriate license.
- In Plesk, go to «Tools & Settings» -> «Mail Server» -> «Antivirus».
- Select «Switch on server-wide Dr.Web antivirus». (If Dr.Web is not installed, Plesk will prompt you to install it).
- Configure scan settings. You can specify which types of files to scan and what actions to take when viruses are detected.
Example: Enable scanning of all incoming and outgoing emails, and when a virus is detected, delete the infected email or quarantine it.
Configuring Mail Filtering Rules
Plesk allows you to create mail filtering rules to automatically process incoming messages. You can use rules to forward mail, mark emails, auto-respond, and perform other actions.
- In Plesk, go to «Mail» -> «Mail Filtering Rules» for the selected mailbox.
- Click «Create Rule».
- Specify the filtering conditions (for example, sender, subject, content) and the actions to take when the conditions are met.
Example: Create a rule to automatically forward all emails sent from sales@example.com to archive@example.com.
Practical Tip: Regularly review your spam filter and antivirus settings and adjust them to your needs. Keep virus databases up to date to ensure maximum protection against new threats.
Diagnosing and Troubleshooting Common Problems
Even with the correct configuration of the mail server, problems can arise with mail delivery, sending emails, or other functions. It is important to be able to diagnose and fix these problems. In this section, we will look at the most common problems and offer solutions.
Mail Delivery Issues
If emails are not being delivered to recipients, you need to check several factors:
- DNS records: Make sure the A-record, MX-record, SPF-record and DKIM-record are configured correctly (see section «Configuring DNS Records for the Mail Server»). Use online tools such as MXToolbox to check records.
- Blacklists: Check if your VPS IP address is blacklisted by spammers. Use online services to check the IP address (for example, whatismyipaddress.com). If the IP address is on the blacklist, contact the list administrators to remove it.
- Mail server logs: View the mail server logs (usually located in `/var/log/mail.log` or `/var/log/maillog`) for errors or warnings. Errors may indicate configuration, authentication, or connection problems with other servers.
- Provider restrictions: Make sure your VPS provider is not blocking sending mail from port 25. If so, use Relay SMTP (see section «Installing and Configuring the Mail Server in Plesk»).
Example: In the logs, you see the error «Relay access denied». This means that your mail server is trying to send mail through another server without authorization. Check the Relay SMTP settings and make sure the correct credentials are specified.
Mail Sending Issues
If you cannot send emails from your mail client, check the following parameters:
- Mail client settings: Make sure your mail client has the correct SMTP server hostname (usually mail.example.com), port (usually 587 or 465), encryption protocol (TLS or SSL), and credentials (username and password).
- Authentication: Make sure SMTP authentication is enabled in the mail client (username and password required).
- Firewall: Make sure the firewall on your VPS is not blocking outgoing connections to SMTP ports (587 or 465).
- Mail server logs: View the mail server logs for authentication or connection errors.
Example: In the mail client, you see the error «Authentication failed». This means that the wrong password or username was entered. Check your credentials and try again. If you forgot your password, reset it via Plesk.
Problems with SpamAssassin and Antivirus
If SpamAssassin is not filtering spam properly, or Dr.Web is not detecting viruses, check the following parameters:
- Updates: Make sure the SpamAssassin and Dr.Web databases are updated to the latest version. Plesk usually performs automatic updates, but you can check the update status in «Tools & Settings» -> «Updates and Upgrades».
- Configuration: Check the SpamAssassin and Dr.Web configuration and make sure they are configured according to your needs (see section «Enabling Spam and Virus Protection»).
- Logs: View the SpamAssassin and Dr.Web logs for errors or warnings. Errors may indicate installation, configuration, or integration issues with the mail server.
Example: You receive a lot of spam that is not filtered by SpamAssassin. Increase the sensitivity of the SpamAssassin filter or add rules to blacklists to block certain addresses or domains.
Practical Tip: Regularly check the mail server, SpamAssassin, and Dr.Web logs to identify and fix problems early on. Use online tools and forums for help and sharing experiences with other Plesk users.
“Diagnosing mail server problems requires patience and attention to detail. Don’t be afraid to refer to documentation and online resources to find a solution.”
Experienced System Administrator