Aller au contenu

Ajouter l'intégration SendGrid

SendGrid est un service infonuagique pour la livraison de courriels transactionnels et marketing. La connexion de cette intégration permet à votre application d’envoyer des courriels de manière programmatique (par exemple, courriels de bienvenue, réinitialisations de mot de passe ou notifications).

Après avoir sélectionné SendGrid dans la liste des intégrations, une fenêtre modale de configuration apparaîtra. Vous devez fournir les informations d’authentification suivantes pour établir la connexion :

Ceci est le jeton d’authentification généré dans votre compte SendGrid.

  • Saisie : Collez votre clé API privée SendGrid dans le champ de texte.
  • Aide : Si vous n’en avez pas, cliquez sur le lien “Où trouver la clé API?” fourni dans la fenêtre modale pour obtenir des instructions sur la façon de la générer.

Spécifiez le contexte d’environnement pour cette intégration.

  • Saisie : Entrez l’identifiant d’environnement (par exemple, Production, Staging ou une balise de configuration spécifique) dans le champ Environnement.

Une fois les champs remplis :

  1. Consultez la barre d’état (affiche actuellement Not Connected).
  2. Cliquez sur le bouton noir Add en bas à droite pour enregistrer les identifiants et activer l’intégration.

Configuration SendGrid

Intégration SendGrid


Configure la clé API SendGrid pour un projet et un environnement spécifiques.

Mutation:

mutation {
sendgrid_configureSendGrid (
apiKey: "SG._api_key_here"
)
}

Envoie un courriel à un ou plusieurs destinataires.

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
}
}
}

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
}
}

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
}
}

Remarque : Le champ content dans les pièces jointes doit être encodé en Base64.

Envoyer un courriel avec catégories et étiquettes

Section intitulée « Envoyer un courriel avec catégories et étiquettes »

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
}
}

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
}
}

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
}
}

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
}
}
}

Envoyer un courriel en utilisant un modèle dynamique

Section intitulée « Envoyer un courriel en utilisant un modèle dynamique »

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
}
}
}

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
}
}

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
}
}

Mutation:

mutation sendgrid_deleteContact {
sendgrid_deleteContact(
email: "contact@example.com"
)
}

Response:

{
"data": {
"sendgrid_deleteContact": true
}
}

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"
}
}
}

Query:

query sendgrid_validateEmail {
sendgrid_validateEmail (
email: "test@example.com"
) {
valid
score
local
domain
reason
suggestions
}
}

Response (avec SendGrid Premium) :

{
"data": {
"sendgrid_validateEmail": {
"valid": true,
"score": 0.95,
"local": "test",
"domain": "example.com",
"reason": "",
"suggestions": []
}
}
}

Response (Validation de base - lorsque SendGrid Premium n’est pas disponible) :

{
"data": {
"sendgrid_validateEmail": {
"valid": true,
"score": 0.8,
"local": "test",
"domain": "example.com",
"reason": "Basic validation (SendGrid premium validation not available)",
"suggestions": []
}
}
}

Remarque : Le point de terminaison de validation de courriel SendGrid (/v3/validations/email) nécessite des permissions spéciales et peut ne pas être disponible dans tous les comptes. Si votre clé API n’a pas accès à ce point de terminaison (erreur 403), le système utilisera automatiquement une validation de base basée sur regex comme solution de secours.


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
}
  1. ID de projet manquant :

    {
    "errors": [{
    "message": "project ID is required in context"
    }]
    }
  2. Configuration non trouvée :

    {
    "errors": [{
    "message": "sendgrid configuration not found for project: xxx, environment: master"
    }]
    }
  3. Clé API invalide :

    {
    "errors": [{
    "message": "sendgrid API error: status 401, body: ..."
    }]
    }

Le point de terminaison des webhooks est disponible à :

  • HTTP: POST http://localhost:8080/webhooks/sendgrid
  • Lambda: POST /webhooks/sendgrid
  1. Allez dans SendGrid Dashboard > Settings > Mail Settings > Event Webhook
  2. Configurez l’URL : https://votre-domaine.com/webhooks/sendgrid
  3. Sélectionnez les événements que vous souhaitez recevoir
  4. Configurez la clé de vérification dans la variable d’environnement WEBHOOK_VERIFICATION_KEY
  • processed: Courriel traité
  • delivered: Courriel livré
  • opened: Courriel ouvert
  • clicked: Lien cliqué
  • bounce: Courriel retourné
  • dropped: Courriel abandonné
  • spamreport: Signalé comme pourriel
  • unsubscribe: Désabonnement