문서로 건너뛰기
Go

이메일 보내기

지금 또는 나중에 한 통, 첨부 파일과 함께, 또는 한 번의 요청으로 백 통.

메시지 보내기

send.go
sent, err := client.Emails.Send(ctx, openemail.Body{	"from":    "Acme Billing <[email protected]>",	"to":      []string{"[email protected]", "[email protected]"},	"replyTo": "[email protected]",	"subject": "Your September invoice",	"html":    "<p>The invoice is attached.</p>",	"text":    "The invoice is attached.",	"tags":    openemail.Body{"invoice": "inv_2026_09_4192"},})if err != nil {	return err} fmt.Println(sent.ID(), sent.String("status"))

to, cc, bcc는 주소 하나 또는 목록을 받으며, 주소는 Ada <[email protected]> 같은 텍스트이거나 email과 name이 있는 map입니다. 본문은 html과 text, 저장된 template, 또는 draftId에서 가져옵니다.

모든 발송은 멱등성 키를 가집니다. 클라이언트는 호출마다 키를 하나 만들고 재시도할 때 다시 쓰므로, 재시도된 요청은 첫 메시지를 재생합니다. 프로세스와 재시작을 넘어서도 보장하려면 openemail.WithIdempotencyKey를 전달하세요.

첨부 파일

attachments.go
invoice, err := os.ReadFile("invoice.pdf")if err != nil {	return err} _, err = client.Emails.Send(ctx, openemail.Body{	"from":    "[email protected]",	"to":      "[email protected]",	"subject": "Your September invoice",	"text":    "The invoice is attached.",	"attachments": []openemail.Body{		{"filename": "invoice.pdf", "content": invoice, "contentType": "application/pdf"},		{"fileId": "file_3f9c2a7b1e4d8f60a5c7b92d"},	},}) return err

content는 []byte 또는 io.Reader를 받고, 클라이언트가 base64로 인코딩합니다. 이미 base64인 텍스트도 받을 수 있습니다. fileId는 client.Files.Upload로 올린 파일을 가리키며, 5 MB보다 큰 파일은 이렇게 보냅니다.

나중에 보내기

schedule.go
scheduled, err := client.Emails.Send(ctx, openemail.Body{	"from":        "[email protected]",	"to":          "[email protected]",	"subject":     "Your invoice is due tomorrow",	"text":        "A reminder that the invoice is due tomorrow.",	"scheduledAt": time.Now().Add(24 * time.Hour),})if err != nil {	return err} if _, err := client.Emails.Reschedule(ctx, scheduled.ID(), time.Now().Add(48*time.Hour)); err != nil {	return err} cancelled, err := client.Emails.Cancel(ctx, scheduled.ID())if err != nil {	return err} fmt.Println(cancelled.String("status"))

scheduledAt은 time.Time, ISO 8601 시각 또는 PT1H 같은 기간을 받습니다. 본문 어디에 있든 time.Time은 UTC의 ISO 8601 시각으로 전송됩니다. 예약된 메시지는 발송되기 전까지 변경하거나 취소할 수 있습니다.

배치 발송

batch.go
result, err := client.Emails.SendBatch(ctx, []openemail.Body{	{"from": "[email protected]", "to": "[email protected]", "subject": "Order AC-4192 has shipped", "text": "It is on its way."},	{"from": "[email protected]", "to": "[email protected]", "subject": "Order AC-4193 has shipped", "text": "It is on its way."},})if err != nil {	return err} fmt.Println(result.Sent, "sent,", result.Failed, "failed") for _, item := range result.Items {	if item.String("status") == "error" {		fmt.Println(item.Int("index"), item.Object("error").String("message"))	}}

일괄 발송은 최대 100통의 메시지를 담으며, 전부 아니면 전무가 아닙니다. 잘못된 주소는 해당 항목만 실패시키고 나머지는 그대로 발송됩니다. 오류에 의존하지 말고 Failed와 각 항목의 status를 확인하세요.