RFC 7208 compliant Go library for parsing and evaluating SPF records.
Requires go 1.23.x or later
Warning This is not a production grade library. it's a project to understand RFC 7208 specs. You might want to look at albertito/spf for a full production grade SPF library.
go get github.com/t0gun/go-spfpackage main
import (
"fmt"
"net"
"github.com/t0gun/go-spf"
)
func main() {
ip := net.ParseIP("192.0.2.1")
res, err := spf.CheckHost(ip, "example.com", "alice@example.com")
if err != nil {
panic(err)
}
fmt.Println(res.Code)
}The parser lives in its own subpackage and can be used directly if you only need to read an SPF record.
import "github.com/t0gun/go-spf/parser"
rec, err := parser.Parse("v=spf1 ip4:203.0.113.0/24 -all")
if err != nil {
// handle parse error
}
fmt.Printf("%+v\n", rec)Please feel free to submit issues, fork the repository and send pull requests!
This project is licensed under the terms of the MIT license.