Sendcorex
Tutorial

E-Mails mit Go (net/smtp) über SMTP senden

Die Standardbibliothek reicht – keine Drittanbieter-Abhängigkeit nötig.

Vom Sendcorex-Team·Aktualisiert am 21. Sept. 2026·7 Min. Lesezeit

Option 1: net/smtp

Die Standardbibliothek von Go bringt alles mit. HTML-Mails brauchen einen MIME-Content-Type-Header, der manuell in den Nachrichtentext geschrieben wird:

package main

import (
    "net/smtp"
    "os"
)

func main() {
    apiKey := os.Getenv("SENDCOREX_API_KEY")
    auth := smtp.PlainAuth("", apiKey, apiKey, "smtp.sendcorex.com")

    to := []string{"customer@example.com"}
    msg := []byte("To: customer@example.com\r\n" +
        "From: Your App <hello@yourdomain.com>\r\n" +
        "Subject: Welcome!\r\n" +
        "Content-Type: text/html; charset=UTF-8\r\n\r\n" +
        "<h1>You are in.</h1>")

    err := smtp.SendMail("smtp.sendcorex.com:587", auth, "hello@yourdomain.com", to, msg)
    if err != nil {
        panic(err)
    }
}

Option 2: REST-API mit net/http

body := []byte(`{"to":"customer@example.com","from":"hello@yourdomain.com","subject":"Welcome!","html":"<h1>You are in.</h1>"}`)

req, _ := http.NewRequest("POST", "https://graph.sendcorex.com/v3.0/emails", bytes.NewBuffer(body))
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", "application/json")

resp, err := http.DefaultClient.Do(req)

Häufige Fehler

SymptomLösung
535 Authentication failedPrüfen Sie, ob der API-Schlüssel korrekt ist und in beiden Feldern von PlainAuth verwendet wird.
Nachricht wird als Klartext angezeigtDer Header Content-Type: text/html muss Teil der Rohnachricht sein, vor der Leerzeile.

Senden Sie Ihre erste E-Mail in wenigen Minuten

Erstellen Sie ein kostenloses Konto, verifizieren Sie Ihre Domain und fügen Sie den Code oben ein.

Keine Kreditkarte nötig