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) AuthParameters & Attributes
| Name | Type | Description |
|---|---|---|
| identity | string | Authorization identity; usually empty. |
| username | string | Synthetic or configured authentication user name. |
| password | string | Authentication password; never log it. |
| host | string | Expected 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) }}