이메일 발송
/v3/smtp/email 엔드포인트를 사용하여 개별 트랜잭션 이메일을 발송합니다.
엔드포인트
POST /v3/smtp/email요청 본문
기본 이메일
{ "sender": { "name": "Your App", }, "to": [ { "name": "John Doe" } ], "subject": "Welcome to our service!", "htmlContent": "<html><body><h1>Welcome!</h1><p>Thank you for signing up.</p></body></html>"}고급 이메일
{ "sender": { "name": "Your App", }, "to": [ { "name": "John Doe" } ], "cc": [ { "name": "CC User" } ], "bcc": [ { } ], "subject": "Order Confirmation #{{order_id}}", "htmlContent": "<html><body><h1>Order Confirmed</h1><p>Your order {{order_id}} has been confirmed.</p></body></html>", "textContent": "Your order {{order_id}} has been confirmed.", "params": { "order_id": "12345" }, "tags": ["transactional", "order-confirmation"], "headers": { "X-Custom-Header": "custom-value" }}코드 예제
JavaScript/Node.js
const brevo = require('@getbrevo/brevo');
const apiInstance = new brevo.TransactionalEmailsApi();apiInstance.setApiKey(brevo.TransactionalEmailsApiApiKeys.apiKey, process.env.BREVO_API_KEY);
const sendEmail = async () => { const sendSmtpEmail = new brevo.SendSmtpEmail();
sendSmtpEmail.subject = "Welcome to our service!"; sendSmtpEmail.htmlContent = "<html><body><h1>Welcome!</h1></body></html>";
try { const result = await apiInstance.sendTransacEmail(sendSmtpEmail); console.log('Email sent:', result); return result; } catch (error) { console.error('Error sending email:', error); throw error; }};Python
import sib_api_v3_sdkfrom sib_api_v3_sdk.rest import ApiException
configuration = sib_api_v3_sdk.Configuration()configuration.api_key['api-key'] = 'YOUR_API_KEY'
api_instance = sib_api_v3_sdk.TransactionalEmailsApi(sib_api_v3_sdk.ApiClient(configuration))
send_smtp_email = sib_api_v3_sdk.SendSmtpEmail( subject="Welcome to our service!", html_content="<html><body><h1>Welcome!</h1></body></html>")
try: api_response = api_instance.send_transac_email(send_smtp_email) print(api_response)except ApiException as e: print("Exception when calling TransactionalEmailsApi->send_transac_email: %s\n" % e)cURL
curl -X POST "https://api.brevo.com/v3/smtp/email" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -H "api-key: YOUR_API_KEY" \ -d '{ "sender": { "name": "Your App", "email": "[email protected]" }, "to": [ { "email": "[email protected]", "name": "John Doe" } ], "subject": "Welcome to our service!", "htmlContent": "<html><body><h1>Welcome!</h1></body></html>" }'응답
성공 응답 (201 Created)
{}오류 응답
잘못된 API 키 (401)
{ "code": "unauthorized", "message": "Invalid API key provided"}잘못된 이메일 형식 (400)
{ "code": "invalid_parameter", "message": "Invalid email format in 'to' field"}요청 한도 초과 (429)
{ "code": "too_many_requests", "message": "Rate limit exceeded"}파라미터
필수 파라미터
| 파라미터 | 유형 | 설명 |
|---|---|---|
sender | object | 발신자 정보 |
to | array | 수신자 객체 배열 |
subject | string | 이메일 제목 |
선택 파라미터
| 파라미터 | 유형 | 설명 |
|---|---|---|
htmlContent | string | 이메일 본문에 사용할 HTML 콘텐츠 |
textContent | string | 이메일 본문에 사용할 텍스트 콘텐츠 |
cc | array | 참조 수신자 |
bcc | array | 숨은 참조 수신자 |
replyTo | object | 회신 주소 |
attachments | array | 첨부 파일 |
params | object | 템플릿 파라미터 |
tags | array | 추적용 이메일 태그 |
headers | object | 사용자 지정 헤더 |
템플릿 변수
이메일 제목과 콘텐츠 안에서 템플릿 변수를 사용할 수 있습니다.
{ "subject": "Welcome {{firstName}}!", "htmlContent": "<h1>Hello {{firstName}} {{lastName}}</h1>", "params": { "firstName": "John", "lastName": "Doe" }}첨부 파일
다음과 같이 요청 본문에 첨부 파일을 포함할 수 있습니다.
{ "attachments": [ { "content": "base64_encoded_content", "name": "invoice.pdf" }, { "url": "https://example.com/document.pdf", "name": "document.pdf" } ]}모범 사례
- 도달률을 높이려면 HTML과 텍스트 콘텐츠를 항상 함께 포함하십시오
- 콘텐츠를 문자열로 이어 붙이는 대신 템플릿 변수를 사용하십시오
- 스팸 필터를 피하려면 정확한 발신자 정보를 포함하십시오
- 추적과 분석을 위해 태그를 추가하십시오
- 발송하기 전에 이메일 주소가 유효한지 검증하십시오
- 재시도 로직으로 오류를 안정적으로 처리하십시오
요청 한도
- 무료 계정: 하루 300건 이메일
- 유료 계정: 요금제에 따름
- 버스트 한도: 분당 100건 이메일
추적
이 엔드포인트로 발송한 이메일은 다음 항목이 자동으로 추적됩니다.
- 전달 상태
- 열람률
- 클릭 추적
- 반송 처리
자세한 분석은 Brevo 대시보드의 통계 → 트랜잭션에서 확인하십시오.
관련 엔드포인트
- 이메일 템플릿
- 첨부 파일
- 이메일 통계