Standard library / net/mail

mail.ParseAddressList()

Parse a comma-separated mailbox list; quoted commas may be part of display names. Check errors before using addresses. Expected stdout: '2 Doe, Ada\n'.

Formal Syntax & Structure

go syntaxgo
func ParseAddressList(list string) ([]*Address, error)

Parameters & Attributes

NameTypeDescription
liststringComma-separated mailbox address list.

Return Value

([]*Address, error)

Mailbox list and error.

Working Example

Example Snippetgo
package main
import (  "fmt"  "net/mail")
func main() {  v := must(mail.ParseAddressList(`"Doe, Ada" <ada@example.invalid>, bob@example.invalid`))  fmt.Println(len(v), v[0].Name)}
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