SendGrid統合の追加
SendGridは、トランザクションメールとマーケティングメールを配信するためのクラウドベースのサービスです。この統合を接続することで、アプリケーションがプログラムでメールを送信できるようになります(例:ウェルカムメール、パスワードリセット、通知)。
統合リストからSendGridを選択すると、設定モーダルが表示されます。接続を確立するには、以下の資格情報を提供する必要があります:
1. APIキー
Section titled “1. APIキー”これは、SendGridアカウント内で生成される認証トークンです。
- 入力: プライベートSendGrid APIキーをテキストフィールドに貼り付けます。
- ヘルプ: お持ちでない場合は、モーダルに表示されている**「APIキーの場所は?」**リンクをクリックして、生成方法の手順を確認してください。
この統合の環境コンテキストを指定します。
- 入力: 環境フィールドに環境識別子(例:
Production、Staging、または特定の設定タグ)を入力します。
フィールドが入力されたら:
- ステータスバーを確認します(現在はNot Connectedと表示されています)。
- 右下の黒いAddボタンをクリックして、資格情報を保存し、統合をアクティブ化します。


SendGrid統合APIリファレンス
Section titled “SendGrid統合APIリファレンス”SendGridの設定
Section titled “SendGridの設定”SendGrid APIキーの設定
Section titled “SendGrid APIキーの設定”特定のプロジェクトと環境のSendGrid APIキーを設定します。
Mutation:
mutation { sendgrid_configureSendGrid ( apiKey: "SG._api_key_here" )}メールの送信
Section titled “メールの送信”シンプルなメールを送信
Section titled “シンプルなメールを送信”1人または複数の受信者にメールを送信します。
Mutation:
mutation sendgrid_sendEmail { sendgrid_sendEmail ( email: { from: { email: "sender@archie.com", name: "Sender Name" }, subject: "Test Email", to: { email: "recipient@gmail.com", name: "Recipient Name" }, content: { type: "text/html", value: "<h1>Hello World</h1><p>This is a test email.</p>" } } ) { messageId success }}Response:
{ "data": { "sendgrid_sendEmail": { "messageId": "sent-1234567890", "success": true } }}CCとBCCを使用してメールを送信
Section titled “CCとBCCを使用してメールを送信”Mutation:
mutation sendgrid_sendEmail { sendgrid_sendEmail ( email: { from: { email: "sender@example.com" name: "Sender Name" } to: [ { email: "recipient@example.com" name: "Recipient Name" } ] cc: [ { email: "cc@example.com" name: "CC Recipient" } ] bcc: [ { email: "bcc@example.com" } ] subject: "Email with CC and BCC" content: [ { type: "text/html" value: "<h1>Hello</h1><p>This email has CC and BCC recipients.</p>" } ] } ) { messageId success }}添付ファイル付きメールを送信
Section titled “添付ファイル付きメールを送信”Mutation:
mutation sendgrid_sendEmail { sendgrid_sendEmail( email: { from: { email: "sender@example.com" name: "Sender Name" } to: [ { email: "recipient@example.com" name: "Recipient Name" } ] subject: "Email with Attachment" content: [ { type: "text/html" value: "<h1>Hello</h1><p>Please find attached file.</p>" } ] attachments: [ { content: "SGVsbG8gV29ybGQ=" type: "text/plain" filename: "document.txt" disposition: "attachment" } ] } ) { messageId success }}注: 添付ファイルのcontentフィールドはBase64でエンコードする必要があります。
カテゴリとタグ付きメールを送信
Section titled “カテゴリとタグ付きメールを送信”Mutation:
mutation sendgrid_sendEmail { sendgrid_sendEmail( email: { from: { email: "sender@example.com" name: "Sender Name" } to: [ { email: "recipient@example.com" name: "Recipient Name" } ] subject: "Categorized Email" content: [ { type: "text/html" value: "<h1>Hello</h1>" } ] categories: ["transactional", "notification"] tags: ["important", "urgent"] } ) { messageId success }}スケジュール送信メール
Section titled “スケジュール送信メール”Mutation:
mutation sendgrid_sendEmail { sendgrid_sendEmail( email: { from: { email: "sender@example.com" name: "Sender Name" } to: [ { email: "recipient@example.com" name: "Recipient Name" } ] subject: "Scheduled Email" content: [ { type: "text/html" value: "<h1>Hello</h1>" } ] sendAt: "2025-12-25T10:00:00Z" } ) { messageId success }}カスタム引数付きメールを送信
Section titled “カスタム引数付きメールを送信”Mutation:
mutation sendgrid_sendEmail { sendgrid_sendEmail( email: { from: { email: "sender@example.com" name: "Sender Name" } to: [ { email: "recipient@example.com" name: "Recipient Name" } ] subject: "Email with Custom Args" content: [ { type: "text/html" value: "<h1>Hello</h1>" } ] customArgs: { orderId: "12345" userId: "67890" campaignId: "abc123" } } ) { messageId success }}一括メール送信
Section titled “一括メール送信”複数のメールを送信
Section titled “複数のメールを送信”Mutation:
mutation sendgrid_sendBulkEmail { sendgrid_sendBulkEmail( emails: { emails: [ { from: { email: "sender@example.com" name: "Sender Name" } to: [ { email: "recipient1@example.com" name: "Recipient 1" } ] subject: "Bulk Email 1" content: [ { type: "text/html" value: "<h1>Email 1</h1>" } ] } { from: { email: "sender@example.com" name: "Sender Name" } to: [ { email: "recipient2@example.com" name: "Recipient 2" } ] subject: "Bulk Email 2" content: [ { type: "text/html" value: "<h1>Email 2</h1>" } ] } ] } ) { messageIds success }}Response:
{ "data": { "sendgrid_sendBulkEmail": { "messageIds": ["sent-1234567890", "sent-1234567891"], "success": true } }}テンプレートを使用したメール送信
Section titled “テンプレートを使用したメール送信”動的テンプレートを使用してメールを送信
Section titled “動的テンプレートを使用してメールを送信”Mutation:
mutation sendgrid_sendTemplate { sendgrid_sendTemplate( email: { from: { email: "sender@example.com" name: "Sender Name" } to: [ { email: "recipient@example.com" name: "Recipient Name" } ] templateId: "d-1234567890abcdef" substitutions: { name: "John Doe" orderNumber: "12345" totalAmount: "$99.99" } } ) { messageId success }}Response:
{ "data": { "sendgrid_sendTemplate": { "messageId": "sent-1234567890", "success": true } }}連絡先を追加
Section titled “連絡先を追加”Mutation:
mutation sendgrid_addContact { sendgrid_addContact( contact: { email: "newcontact@example.com" firstName: "John" lastName: "Doe" customFields: { company: "Acme Corp" phone: "+1234567890" position: "Developer" } listIds: ["list-id-1", "list-id-2"] } )}Response:
{ "data": { "sendgrid_addContact": true }}連絡先を更新
Section titled “連絡先を更新”Mutation:
mutation sendgrid_updateContact { sendgrid_updateContact( contact: { email: "existing@example.com" firstName: "Jane" lastName: "Smith" customFields: { company: "New Company" phone: "+0987654321" } } )}Response:
{ "data": { "sendgrid_updateContact": true }}連絡先を削除
Section titled “連絡先を削除”Mutation:
mutation sendgrid_deleteContact { sendgrid_deleteContact( email: "contact@example.com" )}Response:
{ "data": { "sendgrid_deleteContact": true }}メール統計を取得
Section titled “メール統計を取得”Query:
query sendgrid_getEmailStats { sendgrid_getEmailStats ( startDate: "2025-01-01" endDate: "2025-01-31" ) { opens clicks bounces spamReports delivered startDate endDate }}Response:
{ "data": { "sendgrid_getEmailStats": { "opens": 150, "clicks": 75, "bounces": 5, "spamReports": 2, "delivered": 1000, "startDate": "2025-01-01T00:00:00Z", "endDate": "2025-01-31T00:00:00Z" } }}メールを検証
Section titled “メールを検証”Query:
query sendgrid_validateEmail { sendgrid_validateEmail ( email: "test@example.com" ) { valid score local domain reason suggestions }}Response (SendGrid Premiumを使用):
{ "data": { "sendgrid_validateEmail": { "valid": true, "score": 0.95, "local": "test", "domain": "example.com", "reason": "", "suggestions": [] } }}Response (基本検証 - SendGrid Premiumが利用できない場合):
{ "data": { "sendgrid_validateEmail": { "valid": true, "score": 0.8, "local": "test", "domain": "example.com", "reason": "Basic validation (SendGrid premium validation not available)", "suggestions": [] } }}注: SendGridメール検証エンドポイント (/v3/validations/email) には特別な権限が必要で、すべてのアカウントで利用できるわけではありません。APIキーがこのエンドポイントにアクセスできない場合(エラー403)、システムは自動的に正規表現ベースの基本検証をフォールバックとして使用します。
変数を使用した完全な例
Section titled “変数を使用した完全な例”GraphQL変数を使用した例
Section titled “GraphQL変数を使用した例”Request:
{ "query": "mutation SendEmail($email: EmailInput!) { sendgrid_sendEmail(email: $email) { messageId success } }", "variables": { "email": { "from": { "email": "sender@example.com", "name": "Sender Name" }, "to": [ { "email": "recipient@example.com", "name": "Recipient Name" } ], "subject": "Test Email", "content": [ { "type": "text/html", "value": "<h1>Hello World</h1>" } ] } }}Request:
{ "query": "mutation { sendgrid_sendEmail(email: { from: { email: \"invalid\" }, to: [], subject: \"Test\", content: [] }) { messageId success } }"}Response Error:
{ "errors": [ { "message": "validation error: at least one recipient is required", "path": ["sendgrid_sendEmail"] } ], "data": null}よくあるエラー
Section titled “よくあるエラー”-
プロジェクトIDが不足:
{"errors": [{"message": "project ID is required in context"}]} -
設定が見つかりません:
{"errors": [{"message": "sendgrid configuration not found for project: xxx, environment: master"}]} -
APIキーが無効:
{"errors": [{"message": "sendgrid API error: status 401, body: ..."}]}
Webhooks
Section titled “Webhooks”Webhooksエンドポイント
Section titled “Webhooksエンドポイント”Webhooksエンドポイントは次の場所で利用可能です:
- HTTP:
POST http://localhost:8080/webhooks/sendgrid - Lambda:
POST /webhooks/sendgrid
SendGrid設定
Section titled “SendGrid設定”- SendGrid Dashboard > Settings > Mail Settings > Event Webhookに移動
- URLを設定:
https://your-domain.com/webhooks/sendgrid - 受信したいイベントを選択
- 環境変数
WEBHOOK_VERIFICATION_KEYに検証キーを設定
サポートされているイベント
Section titled “サポートされているイベント”processed: メール処理済みdelivered: メール配信済みopened: メール開封済みclicked: リンククリック済みbounce: メールバウンスdropped: メール破棄spamreport: スパム報告unsubscribe: 配信停止