Documentation
¶
Index ¶
- Constants
- Variables
- type Resolver
- type Result
- func CheckHost(ctx context.Context, ip net.IP, domain, sender, helo string) Result
- func CheckHostWithExplanation(ctx context.Context, ip net.IP, domain, sender, helo string) (Result, string)
- func CheckHostWithExplanationAndResolver(ctx context.Context, ip net.IP, domain, sender, helo string, r Resolver) (Result, string)
- func CheckHostWithResolver(ctx context.Context, ip net.IP, domain, sender, helo string, r Resolver) Result
- func LookupSPF(ctx context.Context, domain string) (spf string, r Result)
Constants ¶
const ( None = Result("NONE") Neutral = Result("NEUTRAL") Pass = Result("PASS") Fail = Result("FAIL") Softfail = Result("SOFTFAIL") TempError = Result("TEMPERROR") PermError = Result("PERMERROR") )
SPF results
Variables ¶
var DNSServer = "8.8.8.8:53"
DNSServer is the DNS server address used by DefaultResolver, in <ip>:<port> format. Default is Google's 8.8.8.8:53. A misconfigured DNSServer will cause SPF checks to return TEMPERROR.
var DNSTimeout = 2 * time.Second
DNSTimeout is the timeout for individual DNS queries made by DefaultResolver. Default is 2 seconds. Adjust for your network conditions.
Functions ¶
This section is empty.
Types ¶
type Resolver ¶
type Resolver interface {
LookupTXT(ctx context.Context, domain string) ([]string, error)
LookupMX(ctx context.Context, domain string) ([]string, error)
LookupA(ctx context.Context, domain string) ([]net.IP, error)
LookupAAAA(ctx context.Context, domain string) ([]net.IP, error)
LookupPTR(ctx context.Context, ip net.IP) ([]string, error)
}
Resolver is the interface for DNS lookups used during SPF evaluation. Implement this interface to inject a custom or mock DNS resolver.
var DefaultResolver Resolver = &dnsResolver{}
DefaultResolver is the package-level Resolver that uses the miekg/dns implementation and the DNSServer global variable.
type Result ¶
type Result string
Result of SPF check
func CheckHost ¶
CheckHost performs an SPF check. ip - the IP address of the SMTP client that is emitting the mail, either IPv4 or IPv6. domain - the domain that provides the sought-after authorization information; initially, the domain portion of the "MAIL FROM" or "HELO" identity. sender - the "MAIL FROM" or "HELO" identity. helo - domain from helo, used as sender domain if sender is not specified.
func CheckHostWithExplanation ¶
func CheckHostWithExplanation(ctx context.Context, ip net.IP, domain, sender, helo string) (Result, string)
CheckHostWithExplanation is like CheckHost but also returns the explanation string if the result is Fail.
func CheckHostWithExplanationAndResolver ¶
func CheckHostWithExplanationAndResolver(ctx context.Context, ip net.IP, domain, sender, helo string, r Resolver) (Result, string)
CheckHostWithExplanationAndResolver is like CheckHostWithResolver but also returns the explanation string.
func CheckHostWithResolver ¶
func CheckHostWithResolver(ctx context.Context, ip net.IP, domain, sender, helo string, r Resolver) Result
CheckHostWithResolver is like CheckHost but uses the provided Resolver for all DNS lookups.
func LookupSPF ¶
LookupSPF returns the SPF TXT record for domain. If no records or more than one record is found, r is set to None or PermError respectively. If the DNS lookup fails, r is TempError.