---
title: Go
description: Send emails via Reloop SMTP using net/smtp in Go.
---
> For the complete documentation index, see [llms-docs.txt](/llms-docs.txt) or the site index [llms.txt](/llms.txt). Full docs corpus: [llms-full-docs.txt](/llms-full-docs.txt). Prefer markdown URLs (append `.md`) for agent consumption. Product skill: [skill.md](/skill.md).


# Go SMTP Integration

Use Go's standard library `net/smtp` package to send emails.

[View complete runnable example on GitHub ↗](https://github.com/reloop-labs/reloop-examples/tree/main/smtp-go)

## Code Example

```go
package main

import (
	"crypto/tls"
	"fmt"
	"net/smtp"
	"os"
)

func main() {
	apiKey := os.Getenv("RELOOP_API_KEY")
	
	// SMTP server configuration
	smtpHost := "smtp.reloop.sh"
	smtpPort := "587"
	
	auth := smtp.PlainAuth("", apiKey, apiKey, smtpHost)
	
	to := []string{"delivered@resend.dev"}
	msg := []byte("To: delivered@resend.dev\r\n" +
		"Subject: Hello from Go net/smtp\r\n" +
		"Content-Type: text/html; charset=UTF-8\r\n" +
		"\r\n" +
		"<p>Congrats on sending your first email via Reloop SMTP using net/smtp!</p>\r\n")
		
	err := smtp.SendMail(smtpHost+":"+smtpPort, auth, "onboarding@reloop.sh", to, msg)
	if err != nil {
		fmt.Println("Error connecting:", err)
		return
	}
	defer conn.Close()

	client, err := smtp.NewClient(conn, host)
	if err != nil {
		fmt.Println("Error creating client:", err)
		return
	}
	defer client.Close()

	if err = client.Auth(auth); err != nil {
		fmt.Println("Auth failed:", err)
		return
	}
	if err = client.Mail(from); err != nil {
		fmt.Println("MAIL FROM failed:", err)
		return
	}
	for _, addr := range to {
		if err = client.Rcpt(addr); err != nil {
			fmt.Println("RCPT TO failed:", err)
			return
		}
	}
	w, err := client.Data()
	if err != nil {
		fmt.Println("DATA failed:", err)
		return
	}
	if _, err = w.Write(msg); err != nil {
		fmt.Println("Write failed:", err)
		return
	}
	if err = w.Close(); err != nil {
		fmt.Println("Close failed:", err)
		return
	}
	_ = client.Quit()

	fmt.Println("Email sent successfully!")
}
```

<RelatedTopics>
  <RelatedTopic icon="smtp" title="SMTP Integration Overview" href="/docs/examples/smtp/introduction" />
  <RelatedTopic icon="siGo" title="Go Gin Integration Guide" href="/docs/examples/go/gin" />
  <RelatedTopic icon="siRust" title="Rust SMTP Guide" href="/docs/examples/smtp/rust" />
</RelatedTopics>
