# Python으로 트랜잭션 이메일 보내기

> Sendtern SDK로 Python에서 트랜잭션 이메일을 보냅니다. Email Playground에서 테스트하고 이메일 ID로 실제 배달을 추적할 수 있습니다.

## 전제 조건

- A Sendtern [API 키](https://sendtern.com/ko/docs/authentication)로 저장 `SENDTERN_API_KEY`
- Python 3.9 이상

1. **SDK 설치**: 프로젝트에서 이 명령을 실행하세요.

```
python -m pip install https://github.com/Sendtern/sendtern-sdks/releases/download/v0.3.0/sendtern-0.3.0-py3-none-any.whl
```

2. **이메일 보내기**: `send.py`를 만들고 `python send.py`로 실행하세요.

```
import os
from sendtern import Sendtern

client = Sendtern(os.environ["SENDTERN_API_KEY"])
result = client.emails.send({
  "from": "Acme <hello@mail.example.com>",
  "to": "you@example.com",
  "subject": "Welcome to Acme",
  "text": "Thanks for signing up."
})
print(result["id"])
```

3. **응답을 확인하십시오**: 성공적인 요청은 이메일 id와 함께 `200 OK`를 반환합니다. 이를 사용하여 나중에 이메일을 찾을 수 있습니다.

```
{
  "id": "47be30ca-24b7-48fb-b35d-ff287b89e66d"
}
```

## 발송 전 테스트

예제를 `preview.py`로 저장한 뒤 `python preview.py`를 실행하세요. 발신 도메인을 설정하기 전에 [Email Playground](https://sendtern.com/ko/dashboard/playground)에서 메시지와 헤더를 확인할 수 있습니다.

```
import os
from sendtern import Sendtern

client = Sendtern(os.environ["SENDTERN_API_KEY"])
result = client.emails.capture({
  "from": "sandbox@sendtern.test",
  "to": "recipient@example.com",
  "subject": "Welcome email preview",
  "html": "<p>Thanks for signing up.</p>"
})
print(result["id"])
```

실제로 발송했다면 반환된 ID로 [배달 이벤트를 확인하세요](https://sendtern.com/ko/docs/statuses). 매월 발송 한도는 [트랜잭션 이메일 요금제](https://sendtern.com/ko/pricing)에 나와 있습니다.

> **tip:** 예제 발신자를 [확인된 도메인](https://sendtern.com/ko/docs/domains)의 주소로 바꿉니다.
