Aggiungere l'Integrazione SendGrid
SendGrid è un servizio basato su cloud per la consegna di e-mail transazionali e di marketing. La connessione di questa integrazione consente alla tua applicazione di inviare e-mail programmaticamente (ad esempio, e-mail di benvenuto, reimpostazioni di password o notifiche).
Passaggi di Configurazione
Sezione intitolata “Passaggi di Configurazione”Dopo aver selezionato SendGrid dall’elenco delle integrazioni, apparirà un modal di configurazione. Devi fornire le seguenti credenziali per stabilire la connessione:
1. Chiave API
Sezione intitolata “1. Chiave API”Questo è il token di autenticazione generato all’interno del tuo account SendGrid.
- Input: Incolla la tua chiave API SendGrid privata nel campo di testo.
- Aiuto: Se non ne hai una, fai clic sul link “Dove trovare la chiave API?” fornito nel modal per le istruzioni su come generarla.
2. Ambiente
Sezione intitolata “2. Ambiente”Specifica il contesto dell’ambiente per questa integrazione.
- Input: Inserisci l’identificatore dell’ambiente (ad esempio,
Production,Stagingo un tag di configurazione specifico) nel campo Ambiente.
Finalizzare la Connessione
Sezione intitolata “Finalizzare la Connessione”Una volta compilati i campi:
- Rivedi la barra di stato (attualmente mostra Not Connected).
- Fai clic sul pulsante nero Add in basso a destra per salvare le credenziali e attivare l’integrazione.


Riferimento API di Integrazione SendGrid
Sezione intitolata “Riferimento API di Integrazione SendGrid”Configurazione di SendGrid
Sezione intitolata “Configurazione di SendGrid”Configurare la Chiave API SendGrid
Sezione intitolata “Configurare la Chiave API SendGrid”Configura la chiave API SendGrid per un progetto e un ambiente specifici.
Mutation:
mutation { sendgrid_configureSendGrid ( apiKey: "SG._api_key_here" )}Invio di E-mail
Sezione intitolata “Invio di E-mail”Inviare E-mail Semplice
Sezione intitolata “Inviare E-mail Semplice”Invia un’e-mail a uno o più destinatari.
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 } }}Inviare E-mail con CC e BCC
Sezione intitolata “Inviare E-mail con CC e 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 }}Inviare E-mail con Allegati
Sezione intitolata “Inviare E-mail con Allegati”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 }}Nota: Il campo content negli allegati deve essere codificato in Base64.
Inviare E-mail con Categorie e Tag
Sezione intitolata “Inviare E-mail con Categorie e Tag”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 }}Inviare E-mail Programmata
Sezione intitolata “Inviare E-mail Programmata”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 }}Inviare E-mail con Argomenti Personalizzati
Sezione intitolata “Inviare E-mail con Argomenti Personalizzati”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 }}Invio di E-mail in Massa
Sezione intitolata “Invio di E-mail in Massa”Inviare Più E-mail
Sezione intitolata “Inviare Più E-mail”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 } }}Inviare E-mail con Modelli
Sezione intitolata “Inviare E-mail con Modelli”Inviare E-mail utilizzando Modello Dinamico
Sezione intitolata “Inviare E-mail utilizzando Modello Dinamico”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 } }}Gestione dei Contatti
Sezione intitolata “Gestione dei Contatti”Aggiungere Contatto
Sezione intitolata “Aggiungere Contatto”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 }}Aggiornare Contatto
Sezione intitolata “Aggiornare Contatto”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 }}Eliminare Contatto
Sezione intitolata “Eliminare Contatto”Mutation:
mutation sendgrid_deleteContact { sendgrid_deleteContact( email: "contact@example.com" )}Response:
{ "data": { "sendgrid_deleteContact": true }}Analitiche e Statistiche
Sezione intitolata “Analitiche e Statistiche”Ottenere Statistiche E-mail
Sezione intitolata “Ottenere Statistiche E-mail”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" } }}Validare E-mail
Sezione intitolata “Validare E-mail”Query:
query sendgrid_validateEmail { sendgrid_validateEmail ( email: "test@example.com" ) { valid score local domain reason suggestions }}Response (con SendGrid Premium):
{ "data": { "sendgrid_validateEmail": { "valid": true, "score": 0.95, "local": "test", "domain": "example.com", "reason": "", "suggestions": [] } }}Response (Validazione di base - quando SendGrid Premium non è disponibile):
{ "data": { "sendgrid_validateEmail": { "valid": true, "score": 0.8, "local": "test", "domain": "example.com", "reason": "Basic validation (SendGrid premium validation not available)", "suggestions": [] } }}Nota: L’endpoint di validazione e-mail di SendGrid (/v3/validations/email) richiede autorizzazioni speciali e potrebbe non essere disponibile in tutti gli account. Se la tua chiave API non ha accesso a questo endpoint (errore 403), il sistema utilizzerà automaticamente una validazione di base basata su regex come fallback.
Esempi Completi con Variabili
Sezione intitolata “Esempi Completi con Variabili”Esempio con Variabili GraphQL
Sezione intitolata “Esempio con Variabili 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>" } ] } }}Gestione degli Errori
Sezione intitolata “Gestione degli Errori”Esempio di Errore
Sezione intitolata “Esempio di Errore”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}Errori Comuni
Sezione intitolata “Errori Comuni”-
ID Progetto mancante:
{"errors": [{"message": "project ID is required in context"}]} -
Configurazione non trovata:
{"errors": [{"message": "sendgrid configuration not found for project: xxx, environment: master"}]} -
Chiave API non valida:
{"errors": [{"message": "sendgrid API error: status 401, body: ..."}]}
Webhooks
Sezione intitolata “Webhooks”Endpoint Webhooks
Sezione intitolata “Endpoint Webhooks”L’endpoint webhooks è disponibile a:
- HTTP:
POST http://localhost:8080/webhooks/sendgrid - Lambda:
POST /webhooks/sendgrid
Configurazione SendGrid
Sezione intitolata “Configurazione SendGrid”- Vai a SendGrid Dashboard > Settings > Mail Settings > Event Webhook
- Configura l’URL:
https://tuo-dominio.com/webhooks/sendgrid - Seleziona gli eventi che desideri ricevere
- Configura la chiave di verifica nella variabile d’ambiente
WEBHOOK_VERIFICATION_KEY
Eventi Supportati
Sezione intitolata “Eventi Supportati”processed: E-mail elaboratadelivered: E-mail consegnataopened: E-mail apertaclicked: Link cliccatobounce: E-mail rimbalzatadropped: E-mail scartataspamreport: Segnalato come spamunsubscribe: Disiscrizione