For the complete documentation index, see llms-docs.txt or the site index llms.txt. Full docs corpus: llms-full-docs.txt. Prefer the markdown version of this page at /docs/examples/smtp/go.md. Product capabilities: skill.md. Docs MCP: /docs/mcp. Site MCP: /mcp.

Go

Send emails via Reloop SMTP using net/smtp in Go.

Go SMTP Integration

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

View complete runnable example on GitHub ↗

Code Example

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!")
}

Was this page helpful?

Edit this page