---
title: How to generate API keys for API and SMTP sending with IAM
description: Learn how to generate API keys for Transactional Email using IAM.
dates:
  validation: 2025-06-02
  posted: 2022-11-07
---
import Requirements from '@macros/iam/requirements.mdx'


This page shows you how to generate [API keys](/iam/concepts/#api-key) with IAM to send [transactional emails](/transactional-email/concepts/#transactional-email) via API and SMTP.

<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 domain name
- [Configured your domain with Transactional Email](/transactional-email/how-to/configure-domain-with-transactional-email/)
- Added [SPF, DKIM](/transactional-email/how-to/authenticate-domain/#how-to-configure-spf-records), and [MX](/transactional-email/how-to/authenticate-domain/#how-to-configure-mx-records) records to your domain

## Generate an API key using IAM and send emails via the API

To send your emails via the API, a valid API key and your Project ID are required.

1. [Create an IAM application](/iam/how-to/create-application/).
2. [Create a policy](/iam/how-to/create-policy/) giving appropriate [permissions](/iam/reference-content/permission-sets/) to carry out actions for Transactional Email in the desired Project(s), with the IAM application attached as a principal.
3. [Create an API key for your application](/iam/how-to/create-api-keys/).
    <Message type="important">
     Make sure you save your secret and access keys as you will need them in the following step.
    </Message>
4. Open a terminal on your computer and type the following command to send an email via the API:

```
cat > mail.json <<EOF
{
    "from": {
        "name": "Alice",
        "email": "alice@my.domain.example.com"
    },
    "to": [
        {
        "name": "Bob",
        "email": "bob@caramail.fr"
        }
    ],
    "subject": "Some subject",
    "text": "Some text.",
    "html": "<p>Some <span style=\"font-weight:bold\">HTML</span>.</p>",
    "project_id": "<project-id>",
    "attachments": [
        {
            "name": "file.html",
            "type": "text/html; charset=\"utf8\"",
            "content": "PCFET0NUWVBFIGh0bWw+CjxodG1sIGxhbmc9ImVuIj4KICAgIDxoZWFkPgogICAgICAgIDxtZXRhIGNoYXJzZXQ9InV0Zi04Ij4KICAgICAgICA8dGl0bGU+dGl0bGU8L3RpdGxlPgogICAgPC9oZWFkPgogICAgPGJvZHk+CiAgICAgICAgPHA+SGVsbG8gPHNwYW4gc3R5bGU9ImNvbG9yOmJsdWUiPndvcmxkPC9zcGFuPiE8L3A+CiAgICA8L2JvZHk+CjwvaHRtbD4="
        }
    ]
}
EOF

curl -X POST "https://api.scaleway.com/transactional-email/v1alpha1/regions/$REGION/emails" \
-H "X-Auth-Token: $TOKEN" \
-d @mail.json
```
<Message type="important">
 - If you have not configured your environment on your local machine, make sure you replace `\<project_id\>` with your [Project ID](/organizations-and-projects/concepts/#project), `$REGION` with `fr-par` and `$TOKEN` with your secret key. If you do not replace the Project ID, the API displays a "permission denied" error message.
 - Make sure you replace the email addresses with yours and your recipient's.
</Message>

The following output should display:

```
{"emails":[{"id":"655c27f2-b2a3-4a9f-8e1f-3e6dc268b1c4","message_id":"3d928e21-187a-4539-b303-403156e37911","project_id":"3e44a89e-1f75-45f5-9b93-422db94165eb","mail_from":"alice@my.domain.example.com","rcpt_to":"bob@caramail.fr","rcpt_type":"to","created_at":"2022-08-01T07:55:36.758671147Z","updated_at":"2022-08-01T07:55:36.758671147Z","status":"new","status_details":"not yet processed","try_count":0,"last_tries":[]}]}%
```

## Generate an API key using IAM to send emails via SMTP

<Message type="note">
 Scaleway supports the `PLAIN` and `LOGIN` authentication methods.
</Message>

The Transactional Email SMTP relay is available at `smtp.tem.scaleway.com` on ports `25`, `587`, `2587` (non TLS), `465` and `2465` (TLS). To send your emails using SMTP, a valid API secret key and your Project ID are required.

1. [Generate an API key](/transactional-email/how-to/generate-api-keys-for-tem-with-iam#generate-an-api-key-using-iam-and-send-emails-via-the-api) as shown above.
2. Authenticate yourself to the server using your Project ID as a username.
3. Use your secret key as a password and start sending emails.


