Standard library / net/mail

mail.ParseAddress()

Parse one RFC 5322 mailbox into display name and address. Syntax acceptance does not verify delivery. Expected stdout: 'Ada ada@example.invalid\n'.

Formal Syntax & Structure

go syntaxgo
func ParseAddress(address string) (*Address, error)

Parameters & Attributes

NameTypeDescription
addressstringOne mailbox address, optionally with display name.

Return Value

(*Address, error)

Parsed mailbox and error.

Working Example

Example Snippetgo
package main
import (  "fmt"  "net/mail")
func main() {  v := must(mail.ParseAddress("Ada <ada@example.invalid>"))  fmt.Println(v.Name, v.Address)}
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