---
title: "Send email from Go over SMTP"
description: "net/smtp with STARTTLS."
url: https://www.unitpost.com/guides/smtp/go
section: SMTP
updated: 2026-08-28
---
# Send email from Go over SMTP

## Connection settings

- **Host**: smtp.unitpost.com
- **Username**: unitpost (always this literal value)
- **Password**: Your Unitpost API key (must carry emails:send)
- **Port (STARTTLS)**: 587 (or 2587 if blocked)
- **Port (implicit TLS)**: 465 (or 2465 if blocked)
- **From address**: Any address on a verified domain

## Send email from Go over SMTP

> net/smtp with STARTTLS.

Go's net/smtp client can STARTTLS to Unitpost on port 587. Username is the literal `unitpost`; password is an API key.

### 1. Send with net/smtp

```go
package main

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

func main() {
    host := "smtp.unitpost.com"
    auth := smtp.PlainAuth("", "unitpost", os.Getenv("UNITPOST_API_KEY"), host)
    to := []string{"customer@example.com"}
    msg := []byte("From: you@yourdomain.com\r\n" +
        "To: customer@example.com\r\n" +
        "Subject: Hello from Go\r\n" +
        "\r\n" +
        "Sent via SMTP.\r\n")

    c, err := smtp.Dial(host + ":587")
    if err != nil {
        panic(err)
    }
    defer c.Close()
    if err = c.StartTLS(&tls.Config{ServerName: host}); err != nil {
        panic(err)
    }
    if err = c.Auth(auth); err != nil {
        panic(err)
    }
    if err = c.Mail("you@yourdomain.com"); err != nil {
        panic(err)
    }
    if err = c.Rcpt(to[0]); err != nil {
        panic(err)
    }
    w, err := c.Data()
    if err != nil {
        panic(err)
    }
    if _, err = w.Write(msg); err != nil {
        panic(err)
    }
    if err = w.Close(); err != nil {
        panic(err)
    }
    _ = c.Quit()
}
```

> Port 587 needs an explicit STARTTLS before AUTH (PLAIN and LOGIN are both accepted). From must be on a verified domain.

### 2. Verify delivery

The message appears in Activity.

## Related

- [Send email from Spring Boot over SMTP](https://www.unitpost.com/guides/smtp/spring): JavaMailSender properties pointed at Unitpost.
- [Send email from .NET over SMTP](https://www.unitpost.com/guides/smtp/dotnet): MailKit pointed at Unitpost.
- [Send email with Nodemailer over SMTP](https://www.unitpost.com/guides/smtp/nodemailer): createTransport pointed at Unitpost — Node, Next.js, or NestJS.
