Jump toUpdate content
How to generate API keys for API and SMTP sending
This page shows you how to generate API keys to send transactional emails via API and SMTP.
You may need certain IAM permissions to carry out some actions described on this page. This means:
- you are the Owner of the Scaleway Organization in which the actions will be carried out, or
- you are an IAM user of the Organization, with a policy granting you the necessary permission sets
- You have an account and are logged into the Scaleway console.
- You have a domain name.
- You have configured your domain with Transactional Email.
- You have added SPF, DKIM and MX records to your domain.
Generate an API key and send emails via the API
To send your emails via the API, a valid API key and your Project ID are required.
-
From the Scaleway console, navigate to the Credentials tab of your Project Dashboard:
-
Scroll down to the API Key section:
-
Click Generate new API key. The following pop-up appears:
-
Add an API Key purpose (for your own reference), or leave this blank. Then click Generate API Key.
The two parts of your API Key (access key and secret key) are displayed. Note the secret key carefully, as it will not be recoverable or viewable after this point.
-
Click OK to confirm.
Important:Make sure you save your secret and access keys as you will need them in the following step.
-
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=" } ]}EOFcurl -X POST "https://api.scaleway.com/transactional-email/v1alpha1/regions/$REGION/emails" \-H "X-Auth-Token: $TOKEN" \-d @mail.json
- If you have not configured your environment in your local machine, make sure you replace
\<project_id\>
with your Project ID,$REGION
withfr-par
and$TOKEN
with your secret key. - Make sure you replace the email addresses with yours and your recipient’s
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 to send emails via SMTP
The Transactional Email SMTP relay is available at smtp.tem.scw.cloud
on ports 25
, 587
, 2587
, 465
(TLS) and 2465
(TLS).
To send your emails using SMTP, a valid API key and your Project ID are required.
- Generate an API key as shown above.
- Authenticate yourself to the server using your Project ID as username.
- Use your secret key as password and start sending emails.
You can only use the PLAIN
authentication method for now, as other methods are not supported.