Depending on your configuration, you might need to use sudo postmap /etc/postfix/sasl_passwd
to be able to launch Postmap.
Configuring an SMTP relay with Transactional Email and Postfix
- smtp
- relay
- postfix
Deploying an SMTP relay on your servers enhances your notification system, ensuring prompt alerts in case of issues, as servers typically report them via email. Moreover, it streamlines email-sending processes for software installed on the server, eliminating the need for complicated email configuration setups.
In this tutorial, you will learn how to set up Postfix and configure Transactional Email’s SMTP service to dispatch emails efficiently. For demonstration purposes, will walk through the configuration process on a MacOS system.
Before you start
To complete the actions presented below, you must have:
- A Scaleway account logged into the console
- Owner status or IAM permissions allowing you to perform actions in the intended Organization
- A valid API key with the right permissions
- Configured your domain with Transactional Email
- Installed Postfix on your local machine
- Installed stunnel on your local machine
- Opened the mail ports on your Instance
- Configured your SMTP server
Configuring Postfix with submission
-
Open a terminal and access the
sasl_passwd
file within Postfix, using the following command:nano /etc/postfix/sasl_passwd -
Copy and paste the following content into the
sasl_passwd
file.[smtp.tem.scw.cloud]:587 <$SCW_USERNAME>:<$SCW_SECRET_KEY> -
Replace
<$SCW_USERNAME>
with your username that displays in the Overview tab of your domain, in the SMTP configuration section. -
Replace
<$SCW_SECRET_KEY>
with your API’s secret key. -
Type
CTRL O
and pressEnter
to save, then typeCTRL X
to exit the file. -
Access the
main.cf
file to configure Postfix:nano /etc/postfix/main.cf -
Add the following lines at the end of the
main.cf
file. Make sure you replace<your-domain-name>
with your own domain name and set therelayhost
to[smtp.tem.scw.cloud]:587
.smtpd_banner = $myhostname ESMTP $mail_namebiff = noappend_dot_mydomain = nomyorigin = <your-domain-name>delay_warning_time = 4alias_maps = hash:/etc/aliasesalias_database = hash:/etc/aliasesmydestination = $myhostname, localhost.$mydomain, localhostsmtp_sasl_auth_enable = yessmtp_sasl_password_maps = hash:/etc/postfix/sasl_passwdsmtp_sasl_security_options = noanonymoussmtp_use_tls = yesrelayhost = [smtp.tem.scw.cloud]:587mynetworks = 127.0.0.0/8inet_interfaces = loopback-onlysmtpd_relay_restrictions = permit_mynetworks,defer_unauth_destination,reject -
Type
CTRL O
and pressEnter
to save, then typeCTRL X
to exit the file. -
Use the following command to launch Postmap:
postmap /etc/postfix/sasl_passwdTip -
Relaunch Postfix using the following command:
sudo postfix reload -
Use the following command to send an email. Make sure that you replace
<your-domain>
with your own domain andrecipient@recipient.com
with your recipient’s email address.date | mail -s "Test from postfix" -a "From:<you@your-domain>" recipient@recipient.comImportantKeep in mind that the subject, body, and HTML of your emails must have at least 10 characters each.
-
Optionally, use
mailq
to see if your mail has been sent. An empty mail queue means that your email has been sent.
Configuring Postfix with a TLS port
Some providers do not let you access port 587. To solve this issue, Scaleway offers non-standard ports that are unlikely to be blocked: 2587
(SMTP) and 2465
(TLS). A workaround is to use stunnel
to be able to use Postfix.
If you are sending emails from an Instance, you must open your Instance’s mail ports.
-
Open a terminal and access the
smtp-wrapper.conf
file using the following command:nano /etc/stunnel/smtp-wrapper.conf -
Copy the following configuration and paste it into the
smtp-wrapper.conf
file:[smtp-tls-wrapper]accept = 2465client = yesconnect = smtp.tem.scw.cloud:2465 -
Type
CTRL O
and pressEnter
to save, then typeCTRL X
to exit the file. -
Start
stunnel
by running the following command:stunnel /etc/stunnel/smtp-wrapper.conf -
Open a new terminal and access your
sasl_passwd
file within Postfix using the following command:nano /etc/postfix/sasl_passwd -
Copy the following configuration and paste it into your file:
[localhost]:2465 <$SCW_USERNAME>:<$SCW_SECRET_KEY> -
Replace
<SCW_USERNAME>
with your username that displays in the Overview tab of your domain, in the SMTP configuration section. -
Replace
<$SCW_SECRET_KEY>
with your API’s secret key. -
Type
CTRL O
and pressEnter
to save, then typeCTRL X
to exit the file. -
Access your
main.cf
file using the following command:nano /etc/postfix/main.cf -
Replace
relayhost = [smtp.tem.scw.cloud]:587
withrelayhost = [localhost]:2465
. -
Type
CTRL O
and pressEnter
to save, then typeCTRL X
to exit the file. -
Use the following command to launch Postmap:
postmap /etc/postfix/sasl_passwdTipDepending on your configuration, you might need to use
sudo postmap /etc/postfix/sasl_passwd
to be able to launch Postmap. -
Relaunch Postfix using the following command:
sudo postfix reload -
Use the following command to send an email. Make sure that you replace
<your-domain>
with your own domain andrecipient@recipient.com
with your recipient’s email address.date | mail -s "Test from postfix" -a "From:<you@your-domain>" recipient@recipient.comImportantKeep in mind that the subject, body, and HTML of your emails must have at least 10 characters.
-
Optionally, use
mailq
to see if your email was sent. An empty mail queue means that your email was sent.