- Настройка пересылки почты в Postfix
- По домену через другой SMTP
- Все исходящие через другой почтовый сервер
- Копирование входящей и исходящей почты
- Дублирование всей почты
- Для исходящих сообщений
- Для входящих сообщений
- Пересылка на другой почтовый ящик
- Setting up an SMTP Relay on Ubuntu
- Why use SMTP relay?
- Steps for setting up an SMTP relay on Ubuntu
- Step 1: Install postfix SMTP server
- Step 2: Creating Mailjet free account for our SMTP relay on Ubuntu
- Step 3: Authenticate your domain name
- Step 4: Configuring postfix for SMTP relay on Ubuntu
- Step 5: Setting up credentials for SASL authentication
- Sending a test email
- Conclusion
- How to Set Up Postfix SMTP Relay on Ubuntu with Sendinblue
- SMTP Relay To The Rescue
- Using Sendinblue To Send 300 Emails Per Day For Free
- Step 1: Create a Sendinblue Account
- Step 2: Set Up Postfix SMTP Relay with Sendinblue
- Step 3: Add Sender Addresses
- Step 4: Set Up SPF/DKIM Authentication in SendinBlue
- Sending Test Email
- Troubleshooting
- Adding Additional Domains
- Wrapping Up
Настройка пересылки почты в Postfix
По домену через другой SMTP
Открываем на редактирование конфигурационный файл postfix:
Редактируем или дописываем:
Теперь нужно открыть на редактирование файл транспорта:
dmosk.ru smtp:[10.10.10.10]:25
it@dmosk.ru smtp:[mail.mailsystem.ru]:25
* где dmosk.ru — домен, для отправки на который используется другой сервер пересылки, а 10.10.10.10 — IP-адрес другого сервера SMTP. it@dmosk.ru и mail.mailsystem.ru — конкретный адрес электронной почты и сервер для его пересылки.
После создаем карту:
И перезапускаем postfix:
systemctl restart postfix
Все исходящие через другой почтовый сервер
По умолчанию, postfix пытается отправить все сообщения напрямую. В данном подразделе мы настроим сервер SMTP, через который будут отправляться все сообщения.
Открываем конфигурационный файл mail.cf:
Находим и редактируем relayhost:
* в данном примере мы будем отправлять все сообщения через smtp.mailsystem.com, подключившись к нему по порту 25. Также можно было указать IP-адрес.
Или если хост пересылки работает по другому порту:
* в данном примере отправка идет через хост, который слушает запросы smtp на порту 26.
Перезапускаем postfix, чтобы настройки применились:
systemctl restart postfix
Копирование входящей и исходящей почты
Дублирование всей почты
Открываем конфигурационный файл mail.cf:
Добавляем следующую строчку:
* вся почта будет дублироваться на электронный ящик backup@domain.ru.
systemctl restart postfix
Для исходящих сообщений
Открываем конфигурационный файл:
* при данной настройке все исходящие сообщения будут копироваться по правилам в файле /etc/postfix/sender_bcc_map;
Теперь открываем данный файл и вносим, примерно, следующее:
user1@domain.ru backup1@domain.ru
@domain2.ru backup2@domain.ru
* в данном примере все сообщения от пользователя user1@domain.ru будут копироваться на почтовый ящик backup1@domain.ru; все письма от домена @domain2.ru будут копироваться на backup2@domain.ru.
И перезапускаем почтовый сервер:
systemctl restart postfix
Для входящих сообщений
Открываем конфигурационный файл:
* при данной настройке все входящие сообщения будут копироваться по правилам в файле /etc/postfix/recipient_bcc_map.
Теперь открываем данный файл и вносим, примерно, следующее:
user1@domain.ru backup1@domain.ru
@domain2.ru backup2@domain.ru
* в данном примере все сообщения пользователю user1@domain.ru будут копироваться на почтовый ящик backup1@domain.ru; все письма на домен @domain2.ru будут копироваться на backup2@domain.ru.
И перезапускаем почтовый сервер:
systemctl restart postfix
Пересылка на другой почтовый ящик
Открываем конфигурационный файл:
* при данной настройке все входящие сообщения будут копироваться по правилам в файле /etc/postfix/virtual.
Теперь открываем данный файл и вносим, примерно, следующее:
Setting up an SMTP Relay on Ubuntu
In this module, we’ll take a look at how to setup an SMTP Relay on Ubuntu. Before we get started, let’s understand what an SMP relay is and then get right into the setup.
Table of Contents
Why use SMTP relay?
SMTP relay routes your emails through a third-party service provider which will send emails through their servers. It is often great to setup SMTP relay for large volumes of emails instead of managing your own infrastructure.
With SMTP relays, you do not have the manage the servers to there are no downtimes, email reaches to the inbox and not into spam, you can send larger email volumes and also view analytics on your dashboard.
Overall setting up SMTP relay can be really useful, as it can help in cutting costs and improving email deliverability.
Steps for setting up an SMTP relay on Ubuntu
In this tutorial, we’ll demonstrate setting up SMTP relay with Mailjet’s free plan on a Ubuntu server. But the steps should be similar for the other service providers as well.
Step 1: Install postfix SMTP server
First we’ll need to setup a local SMTP server, which we’ll do so by setting up postfix which is a popular open source mail transfer agent. We can easily install postfix by running the apt command:
When you enter the command above, postfix‘s configuration window will open, like below:
The postfix configuration asks you for what kind of a service are you setting up postfix for, so it can configure itself for your best needs. In this tutorial we’ll go with “Internet Site” as we are required to send emails over the internet. So you can simply press Enter key.
Now next you are required to enter the domain name for your email service, it should be a fully qualified domain name (FQDN).
and then it will run the script to put up the best configuration according to your needs and the inputted data.
Step 2: Creating Mailjet free account for our SMTP relay on Ubuntu
We are done installing with postfix but before we continue configuring postfix we’ll need to first get the required credentials to be successfully able to configure postfix for SMTP relay.
For demonstration, we’ll register a free account on Mailjet. But the process will be similar for the other providers as well, once you are done with the registration.
Choose as Developer, and in “Sending methods” choose “SMTP relay”. Once you have chosen SMTP relay as your sending method. They’ll give give you the required details:
Step 3: Authenticate your domain name
You must authenticate your domain name to improve emails deliverability and that your emails don’t end up in spam.
Step 4: Configuring postfix for SMTP relay on Ubuntu
Now we have the required credentials, so we can get started to configure postfix to send all the emails through the SMTP relay.
We need to make following changes in the /etc/postfix/main.cf which is the postfix’s configuration file. First you need to find relayhost in main.cf configuration and enter your relay host,
In our case, we’ve used the host provided by the Mailjet. But it will be different for different providers, so make sure you enter the right relayhost.
Now add the following to the main.cf file, to enable SASL authentication,
You can read more about these settings in the postfix’s documentation. Once you are done, save the file.
Step 5: Setting up credentials for SASL authentication
Now we’ll create a file at /etc/postfix/sasl_passwd and add the credentials in the following format in plain text form:
Now we’ll hash the database file using the postmap command:
Next, restart postfix ,
We are done with configuring SMTP relay!
Sending a test email
So that now we are done with configuring SMTP relay, now it’s time to put it to test, for this purpose we’ll send a test email using mail command, if you cannot find mail command, you can simply install it by install mailutils with apt command:
now to send an email enter:
If you receive the email, congratulations you have successfully setup SMTP relay server! Incase you didn’t receive email, you can find mail logs in /var/log/mail.log which will help in troubleshooting.
Conclusion
And that brings us to the end of this article! We hope you enjoyed learning with us! There’s a lot more in store for Linux tutorials in the future so stay tuned!
How to Set Up Postfix SMTP Relay on Ubuntu with Sendinblue
This tutorial is going to show you how to set up Postfix SMTP relay with Sendinblue on Ubuntu. Postfix is a popular open-source SMTP server. Previously I wrote an article on how to easily set up a full-blown email server on Ubuntu with iRedMail, which helped a lot of readers run their own email servers.
However, some readers told me that port 25 is blocked by hosting provider/ISP as a way to control email spam, so they couldn’t send emails. Vultr would unblock port 25 if you ask them to, and ScalaHosting doesn’t block port 25 at all, so I recommend using ScalaHosting VPS. Some other hosting providers/ISPs like DigitalOcean would refuse to unblock port 25.
This tutorial works on all current Ubuntu releases, including Ubuntu 22.04, Ubuntu 20.04, and Ubuntu 18.04.
SMTP Relay To The Rescue
You can bypass port 25 and send emails via SMTP relay because it uses TCP port 587. With SMTP relay, your own email server doesn’t directly send email to the destination email address. Instead, there’s an intermediate mail server, also known as smart host or relay host, that sends emails on your behalf. Your email server communicates with the relay host on TCP port 587, then the relay host communicates with the recipient’s mail server on port 25.
SMTP relay can also help you get around anti-spam blacklists, if your IP address is blacklisted for whatever reason. The recipient’s mail server checks the relay host’s IP address against public anti-spam blacklists, instead of your server IP address and because SMTP relay services maintain good IP reputation, so your emails can get through IP blacklists.
Using Sendinblue To Send 300 Emails Per Day For Free
There are several email service providers (ESP) that can act as relay host. Some charge a little fee, some offer free quotas every month. In this article, I’d like to show you how to use Sendinblue, which is an email service provider that allows you to send 300 emails per day for free.
The nice thing about Sendinblue is that it doesn’t require you to enter your credit card details when you use the free SMTP relay service. There are other ESPs that offer free quota every month but requires you to enter credit card details. I know how frustrated it can be when you don’t have a credit card. Sendinblue is also easier to set up, compared to other ESPs.
Step 1: Create a Sendinblue Account
Create a free account at sendinblue.com. Once you complete your user profile, click the Transactional tab, you will get your SMTP settings. If there’s no SMTP settings, you need to contact Sendinblue customer service in order to activate the transactional email service.
Now you need to configure your Postfix SMTP server to use the Sendinblue SMTP settings.
Step 2: Set Up Postfix SMTP Relay with Sendinblue
First, let’s install Postfix SMTP server on Ubuntu with the following command. If Postfix is already running on your server, then skip installing Postfix, but you still need to install the libsasl2-modules package.
When you see the following message, press the Tab key and press Enter.
Then choose the second option: Internet Site .
Next, set the system mail name. For example, I enter my domain name linuxbabe.com .
After Postfix is installed, open the main configuration file with a command-line text editor like Nano.
Find the following line.
By default, its value is empty. Set the value of relayhost to [smtp-relay.sendinblue.com]:587 .
Then add the following lines to the end of this file.
Save and close the file. Then create the /etc/postfix/sasl_passwd file.
Add the SMTP relay host and SMTP credentials to this file like below. Replace smtp_username and smtp_password with the SMTP username and password given by SendinBlue. Note there’s a colon between the username and password.
Be careful that you should not use the main Sendinblue account password. Instead, you should find the SMTP password in the Sendinblue transactional tab.
Save and close the file. Then create the corresponding hash db file with postmap .
Now you should have a file /etc/postfix/sasl_passwd.db . Restart Postfix for the changes to take effect.
By default, sasl_passwd and sasl_passwd.db file can be read by any user on the server. Change the permission to 600 so only root can read and write to these two files.
From now on, Postfix will send emails via Sendinblue.
Step 3: Add Sender Addresses
Click the drop-down menu on the upper-right corner of your Sendinblue account dashboard and select the Senders & IPs tab to add your domain and sender address.
Step 4: Set Up SPF/DKIM Authentication in SendinBlue
In this step, we need to set up SPF and DKIM record, which is strongly recommended if you want your emails to land in recipient’s inbox rather than spam folder.
- SPF: Sender Policy Framework. This is a DNS record that specifies what IP addresses are allowed to send email for your domain.
- DKIM: DomainKeys Identified Mail. Sendinblue will digitally sign your emails with a private key. The DKIM record contains a public key that allows recipient’s email server to verify the signature.
In your SendinBlue dashboard, click your account name on the upper-right corner, then click Senders & IPs . Select the Domains tab -> Manage -> Authenticate this domain .
A popup appears. You need to add the first 3 records for your domain.
After SPF and DKIM records are created, wait a few moments and click the RECORD ADDED. PLEASE VERIFY IT button. Depending on your DNS hosting service, your new DNS records can take some time to propagate on the Internet.
- Go to https://dnsmap.io check if your DNS records are propagated to the Internet.
- For DKIM record, go to https://www.dmarcanalyzer.com/dkim/dkim-check/, enter mail as the selector and enter your domain name to check DKIM record propagation and if there’s error in your DKIM record.
If SPF and DKIM records are set up correctly and they are verified, your domain becomes authenticated in Sendinblue.
Sending Test Email
Now we can send a test email with mailx command like below.
You can also send a test email from your webmail client or desktop mail client. It is also a good idea to test your email score at https://www.mail-tester.com. As you can see, I got a perfect score.
Troubleshooting
Relay Access Denied
If your email wasn’t delivered and you found the following message in the mail log ( /var/log/mail.log ),
then you might need to edit the /etc/postfix/sasl_passwd file and remove the port number after the hostname like below.
Save and close the file. Then build the index file again.
Restart Postfix for the changes to take effect.
Now you can flush the email queue (attempt to deliver the previous emails).
Sendinblue SMTP account is not yet activated
If you found the following message in the mail log ( /var/log/mail.log ),
Then contact Sendinblue customer service to activate the transactional email service.
Adding Additional Domains
If you set up a mail server on a new host for a new domain name, and you want to set up SMTP relay for this new domain name, then simply follow step 2, step 3 and step 4 again.
Wrapping Up
That’s it! I hope this tutorial helped you set up Postfix SMTP relay on Ubuntu to bypass port 25 or IP blacklists. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks. Take care 🙂