Standard library / net/smtp

smtp.PlainAuth()

Create PLAIN authentication bound to the expected host. It refuses cleartext remote connections; localhost is a special case. Require verified TLS in real deployments. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func PlainAuth(identity, username, password, host string) Auth

Parameters & Attributes

NameTypeDescription
identitystringAuthorization identity; usually empty.
usernamestringSynthetic or configured authentication user name.
passwordstringAuthentication password; never log it.
hoststringExpected SMTP server hostname for authentication.

Return Value

Auth

Authentication mechanism implementing PLAIN.

Working Example

Example Snippetgo
package main
import (  "fmt"  "net/smtp")
func main() {  a := smtp.PlainAuth("", "demo", "synthetic", "fixture.invalid")  _, _, e := a.Start(&smtp.ServerInfo{Name: "fixture.invalid", TLS: false})  fmt.Println(e != nil)}
func must[T any](v T, e error) T {  if e != nil {    panic(e)  }  return v}func check(e error) {  if e != nil {    panic(e)  }}
Go Reference