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?
- Need help? Contact Support.
- Chat with Reloop developers on Discord.
- Check out our changelog.
- Questions? Contact Sales.
- LLM? Read llms.txt.