Documentation
¶
Overview ¶
Package mail implements parsing of mail messages.
For the most part, this package follows the syntax as specified by RFC 5322 and extended by RFC 6532. Notable divergences:
- Obsolete address formats are not parsed, including addresses with embedded route information.
- The full range of spacing (the CFWS syntax element) is not supported, such as breaking addresses across lines.
- No unicode normalization is performed.
- The special characters ()[]:;@\, are allowed to appear unquoted in names.
- A leading From line is permitted, as in mbox format (RFC 4155).
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrHeaderNotPresent = errors.New("mail: header not in message")
Functions ¶
Types ¶
type Address ¶
Address represents a single mail address. An address such as "Barry Gibbs <bg@example.com>" is represented as Address{Name: "Barry Gibbs", Address: "bg@example.com"}.
func ParseAddress ¶ added in go1.1
ParseAddress parses a single RFC 5322 address, e.g. "Barry Gibbs <bg@example.com>"
Example ¶
package main
import (
"fmt"
"log"
"net/mail"
)
func main() {
e, err := mail.ParseAddress("Alice <alice@example.com>")
if err != nil {
log.Fatal(err)
}
fmt.Println(e.Name, e.Address)
}
Output: Alice alice@example.com
func ParseAddressList ¶ added in go1.1
ParseAddressList parses the given string as a list of addresses.
Example ¶
package main
import (
"fmt"
"log"
"net/mail"
)
func main() {
const list = "Alice <alice@example.com>, Bob <bob@example.com>, Eve <eve@example.com>"
emails, err := mail.ParseAddressList(list)
if err != nil {
log.Fatal(err)
}
for _, v := range emails {
fmt.Println(v.Name, v.Address)
}
}
Output: Alice alice@example.com Bob bob@example.com Eve eve@example.com
type AddressParser ¶ added in go1.5
type AddressParser struct {
// WordDecoder optionally specifies a decoder for RFC 2047 encoded-words.
WordDecoder *mime.WordDecoder
}
An AddressParser is an RFC 5322 address parser.
type Header ¶
A Header represents the key-value pairs in a mail message header.
func (Header) AddressList ¶
AddressList parses the named header field as a list of addresses.
func (Header) Get ¶
Get gets the first value associated with the given key. It is case insensitive; CanonicalMIMEHeaderKey is used to canonicalize the provided key. If there are no values associated with the key, Get returns "". To access multiple values of a key, or to use non-canonical keys, access the map directly.