콘텐츠로 이동

SendGrid 통합 추가

SendGrid는 트랜잭션 및 마케팅 이메일을 전달하기 위한 클라우드 기반 서비스입니다. 이 통합을 연결하면 애플리케이션에서 프로그래밍 방식으로 이메일을 보낼 수 있습니다(예: 환영 이메일, 비밀번호 재설정 또는 알림).

통합 목록에서 SendGrid를 선택하면 구성 모달이 나타납니다. 연결을 설정하려면 다음 자격 증명을 제공해야 합니다:

SendGrid 계정 내에서 생성된 인증 토큰입니다.

  • 입력: 비공개 SendGrid API 키를 텍스트 필드에 붙여넣으세요.
  • 도움말: 키가 없는 경우 모달에 제공된 “API 키를 찾을 위치는?” 링크를 클릭하여 생성 방법에 대한 지침을 확인하세요.

이 통합의 환경 컨텍스트를 지정합니다.

  • 입력: 환경 필드에 환경 식별자(예: Production, Staging 또는 특정 구성 태그)를 입력하세요.

필드가 입력되면:

  1. 상태 표시줄을 검토하세요(현재 Not Connected 표시).
  2. 오른쪽 하단의 검은색 Add 버튼을 클릭하여 자격 증명을 저장하고 통합을 활성화하세요.

SendGrid 구성

SendGrid 통합


특정 프로젝트 및 환경에 대한 SendGrid API 키를 구성합니다.

Mutation:

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

한 명 또는 여러 명의 수신자에게 이메일을 전송합니다.

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

참고: 첨부 파일의 content 필드는 Base64로 인코딩해야 합니다.

카테고리 및 태그와 함께 이메일 전송

섹션 제목: “카테고리 및 태그와 함께 이메일 전송”

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

동적 템플릿을 사용하여 이메일 전송

섹션 제목: “동적 템플릿을 사용하여 이메일 전송”

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": {
"send grid_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 (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), 시스템은 자동으로 정규 표현식 기반 기본 검증을 대체 수단으로 사용합니다.


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 누락:

    {
    "errors": [{
    "message": "project ID is required in context"
    }]
    }
  2. 구성을 찾을 수 없음:

    {
    "errors": [{
    "message": "sendgrid configuration not found for project: xxx, environment: master"
    }]
    }
  3. API 키 무효:

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

Webhooks 엔드포인트는 다음 위치에서 사용할 수 있습니다:

  • HTTP: POST http://localhost:8080/webhooks/sendgrid
  • Lambda: POST /webhooks/sendgrid
  1. SendGrid Dashboard > Settings > Mail Settings > Event Webhook으로 이동
  2. URL 구성: https://your-domain.com/webhooks/sendgrid
  3. 수신할 이벤트 선택
  4. 환경 변수 WEBHOOK_VERIFICATION_KEY에 검증 키 구성
  • processed: 이메일 처리됨
  • delivered: 이메일 전달됨
  • opened: 이메일 열림
  • clicked: 링크 클릭됨
  • bounce: 이메일 반송됨
  • dropped: 이메일 삭제됨
  • spamreport: 스팸 신고됨
  • unsubscribe: 구독 취소