---
title: Configuring an SMTP relay with Transactional Email and Postfix
description: This page shows you how to configure an SMTP relay with Scaleway's Transactional Email and Postfix
tags: smtp relay postfix
products:
  - transactional-email
  - instances
dates:
  validation: 2025-03-06
  posted: 2023-08-08
  validation_frequency: 12
difficulty: beginner
usecase:
  - set-up-and-test
ecosystem:
  - third-party
---
import Requirements from '@macros/iam/requirements.mdx'


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](https://en.wikipedia.org/wiki/Postfix_(software)) and configure Transactional Email's SMTP service to dispatch emails efficiently.
For demonstration purposes, will walk through the configuration process on a MacOS system.

<Requirements />

- A Scaleway account logged into the [console](https://console.scaleway.com)
- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization
- A valid [API key](/iam/how-to/create-api-keys/) with the right [permissions](/iam/reference-content/permission-sets/)
- [Configured your domain with Transactional Email](/transactional-email/how-to/configure-domain-with-transactional-email/)
- Installed [Postfix](https://ubuntu.com/server/docs/mail-postfix) on your local machine
- Installed [stunnel](https://www.stunnel.org/downloads.html) on your local machine
- Opened [the mail ports on your Instance](/instances/how-to/send-emails-from-your-instance/)
- Configured your SMTP server

## Configuring Postfix with submission

1. Open a terminal and access the `sasl_passwd` file within Postfix, using the following command:

    ```bash
    nano /etc/postfix/sasl_passwd
    ```
2. Copy and paste the following content into the `sasl_passwd` file.

    ```bash
    [smtp.tem.scaleway.com]:587 <$SCW_USERNAME>:<$SCW_SECRET_KEY>
    ```
3. Replace `<$SCW_USERNAME>` with your username that displays in the **Overview** tab of your domain, in the SMTP configuration section.
4. Replace `<$SCW_SECRET_KEY>` with your API's secret key.
5. Type `CTRL O` and press `Enter` to save, then type `CTRL X` to exit the file.
6. Access the `main.cf` file to configure Postfix:
    ```bash
    nano /etc/postfix/main.cf
    ```
7. 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 the `relayhost` to `[smtp.tem.scaleway.com]:587`.

    ```bash
    smtpd_banner = $myhostname ESMTP $mail_name
    biff = no
    append_dot_mydomain = no
    myorigin = <your-domain-name>
    delay_warning_time = 4
    alias_maps = hash:/etc/aliases
    alias_database = hash:/etc/aliases
    mydestination = $myhostname, localhost.$mydomain, localhost
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
    smtp_sasl_security_options = noanonymous
    smtp_use_tls = yes
    relayhost = [smtp.tem.scaleway.com]:587
    mynetworks = 127.0.0.0/8
    inet_interfaces = loopback-only
    smtpd_relay_restrictions = permit_mynetworks,defer_unauth_destination,reject
    ```
8. Type `CTRL O` and press `Enter` to save, then type `CTRL X` to exit the file.
9. Use the following command to launch Postmap:
    ```bash
    postmap /etc/postfix/sasl_passwd
    ```
    <Message type="tip">
     Depending on your configuration, you might need to use `sudo postmap /etc/postfix/sasl_passwd` to be able to launch Postmap.
    </Message>
10. Relaunch Postfix using the following command:
    ```bash
    sudo postfix reload
    ```
11. Use the following command to send an email. Make sure that you replace `<your-domain>` with your own domain and `recipient@recipient.com` with your recipient's email address.
    ```bash
    date | mail -s "Test from postfix" -a "From:<you@your-domain>" recipient@recipient.com
    ```
12. 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.

<Message type="important">
 If you are sending emails from an Instance, you must [open your Instance's mail ports](/instances/how-to/send-emails-from-your-instance/).
</Message>

1. Open a terminal and access the `smtp-wrapper.conf` file using the following command:
    ```bash
    nano /etc/stunnel/smtp-wrapper.conf
    ```
2. Copy the following configuration and paste it into the `smtp-wrapper.conf` file:
    ```bash
    [smtp-tls-wrapper]
    accept = 2465
    client = yes
    connect = smtp.tem.scaleway.com:2465
    ```
3. Type `CTRL O` and press `Enter` to save, then type `CTRL X` to exit the file.
4. Start `stunnel` by running the following command:
    ```
    stunnel /etc/stunnel/smtp-wrapper.conf
    ```
5. Open a new terminal and access your `sasl_passwd` file within Postfix using the following command:
    ```bash
    nano /etc/postfix/sasl_passwd
    ```
5. Copy the following configuration and paste it into your file:
    ```bash
    [localhost]:2465 <$SCW_USERNAME>:<$SCW_SECRET_KEY>
    ```
6. Replace `<SCW_USERNAME>` with your username that displays in the **Overview** tab of your domain, in the SMTP configuration section.
7. Replace `<$SCW_SECRET_KEY>` with your API's secret key.
8. Type `CTRL O` and press `Enter` to save, then type `CTRL X` to exit the file.
9. Access your `main.cf` file using the following command:
    ```bash
    nano /etc/postfix/main.cf
    ```
8. Replace `relayhost = [smtp.tem.scaleway.com]:587` with `relayhost = [localhost]:2465`.
9. Type `CTRL O` and press `Enter` to save, then type `CTRL X` to exit the file.
10. Use the following command to launch Postmap:
    ```bash
    postmap /etc/postfix/sasl_passwd
    ```
    <Message type="tip">
     Depending on your configuration, you might need to use `sudo postmap /etc/postfix/sasl_passwd` to be able to launch Postmap.
    </Message>
11. Relaunch Postfix using the following command:
    ```bash
    sudo postfix reload
    ```
12. Use the following command to send an email. Make sure that you replace `<your-domain>` with your own domain and `recipient@recipient.com` with your recipient's email address.
    ```bash
    date | mail -s "Test from postfix" -a "From:<you@your-domain>" recipient@recipient.com
    ```
13. Optionally, use `mailq` to see if your email was sent. An empty mail queue means that your email was sent.