はじめに
最初のメールを送信
テンプレートを公開し、API キーを作成して最初のメールを送信します。
1. プロジェクトを準備
初期状態ではサンドボックスモードになっており、実際にメールを送信せずにテストできます。本番配信を始めるには、ダッシュボードの送信設定を完了し、本番送信を有効にしてください。
2. テンプレートを公開
プロジェクトでテンプレートを選んで公開します。エディターでテンプレートのキーと変数名を確認してください。
3. API キーを作成
プロジェクトの API キー画面でキーを作成し、サーバーの環境変数 SENDERY_API_KEY に保存します。ブラウザーのコードやソース管理には含めないでください。
Shell
export SENDERY_API_KEY="your_project_api_key"4. メールを送信
cURL または利用する言語の SDK を使います。your-template をテンプレートのキーに、data をその変数に、宛先をご自身のアドレスに置き換えてください。
cURL
curl https://sendery.co/api/v1/emails \
-H "Authorization: Bearer $SENDERY_API_KEY" \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{
"to": "[email protected]",
"template": "your-template",
"data": {"name": "Alex", "action_url": "https://example.com/start"}
}'PHP
require 'vendor/autoload.php';
use Sendery\Client;
$sendery = new Client(getenv('SENDERY_API_KEY'));
$receipt = $sendery->send(
to: '[email protected]',
template: 'your-template',
data: ['name' => 'Alex', 'action_url' => 'https://example.com/start'],
);
echo $receipt['id'];JavaScript
import { Sendery } from '@sendery/sdk';
const apiKey = process.env.SENDERY_API_KEY;
if (!apiKey) throw new Error('Set SENDERY_API_KEY on your server.');
const sendery = new Sendery(apiKey);
const receipt = await sendery.send({
to: '[email protected]',
template: 'your-template',
data: { name: 'Alex', action_url: 'https://example.com/start' },
});
console.log(receipt.id);Go
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/sendery-co/sendery-go"
)
func main() {
client, err := sendery.NewClient(os.Getenv("SENDERY_API_KEY"))
if err != nil {
log.Fatal(err)
}
receipt, err := client.Send(context.Background(), sendery.SendEmailInput{
To: "[email protected]",
Template: "your-template",
Data: map[string]any{
"name": "Alex",
"action_url": "https://example.com/start",
},
})
if err != nil {
log.Fatal(err)
}
fmt.Println(receipt.ID)
}Python
import os
from sendery import Sendery
sendery = Sendery(os.environ["SENDERY_API_KEY"])
receipt = sendery.send(
to="[email protected]",
template="your-template",
data={"name": "Alex", "action_url": "https://example.com/start"},
)
print(receipt["id"])Java
import co.sendery.Sendery;
import java.util.Map;
public class SendEmail {
public static void main(String[] args) {
var sendery = new Sendery(System.getenv("SENDERY_API_KEY"));
var receipt = sendery.send("[email protected]", "your-template", Map.of(
"name", "Alex",
"action_url", "https://example.com/start"
));
System.out.println(receipt.id());
}
}Kotlin
import co.sendery.Sendery
fun main() {
val sendery = Sendery(System.getenv("SENDERY_API_KEY"))
val receipt = sendery.send("[email protected]", "your-template", mapOf(
"name" to "Alex",
"action_url" to "https://example.com/start"
))
println(receipt.id())
}5. 結果を確認
202 はリクエストの受付を示します。返された id を保存して配信状態を確認します。サンドボックスのレスポンスには sandbox_url も含まれます。ログインした状態で開くとメールを確認できます。サンドボックスのメール内容は1日間保存されます。
202 · application/json
{
"id": "35a6b227-1748-412e-8651-430492201670",
"status": "queued",
"sandbox_url": "https://sendery.co/en/app/projects/5656/activity/35a6b227-1748-412e-8651-430492201670"
}6. メールの状態を取得
以下の ID を送信時に返された ID に置き換えてください。
Shell
curl https://sendery.co/api/v1/emails/35a6b227-1748-412e-8651-430492201670 \
-H "Authorization: Bearer $SENDERY_API_KEY" \
-H 'Accept: application/json'