https://github.com/t0gun/go-spf
Go library for analyzing, and evaluating SPF records
https://github.com/t0gun/go-spf
email-verification go library spf
Last synced: 5 months ago
JSON representation
Go library for analyzing, and evaluating SPF records
- Host: GitHub
- URL: https://github.com/t0gun/go-spf
- Owner: t0gun
- License: mit
- Created: 2025-04-16T12:38:51.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-07-29T02:49:32.000Z (6 months ago)
- Last Synced: 2025-07-29T04:36:42.609Z (6 months ago)
- Topics: email-verification, go, library, spf
- Language: Go
- Homepage:
- Size: 81.1 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-spf
[](https://github.com/t0gun/go-spf/actions/workflows/go-test.yaml)
[](https://pkg.go.dev/github.com/t0gun/go-spf)
RFC 7208 compliant Go library for parsing and evaluating SPF records.
> Requires go 1.23.x or later
> **Warning**
> This project is an early proof of concept. The evaluator currently supports `ip4`, `ip6` and `all` mechanisms with
> left-to-right, first-match semantics. It returns the qualifier of the first matching mechanism and falls back to
`Neutral` only when nothing matches. Features like `include`, `a`, `mx`, `exists`, `ptr`, `redirect`, DNS lookup limits
> and macros are not implemented yet.
## Installation
```shell
go get github.com/t0gun/go-spf
```
## Usage
### Checking a host
```go
package 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)
}
```
### Parsing a record
The parser lives in its own subpackage and can be used directly if you only
need to read an SPF record.
```go
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)
```
## Contributing
Please feel free to submit issues, fork the repository and send pull requests!
## License
This project is licensed under the terms of the MIT license.