spf

package module
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2022 License: MIT Imports: 8 Imported by: 0

README

SPF package for Go/GoLang

This package provides Sender Policy Framework (SPF) check for Go based on RFC 7208.

TODO

Still have some issues to fix/add, like exp= modifier etc.

Example

package main

import (
    "net"

    "github.com/mileusna/spf"
)

func main() {
    // optional, set DNS server which will be used by resolver.
    // Default is Google's 8.8.8.8:53
    spf.DNSServer = "1.1.1.1:53"

    ip := net.ParseIP("123.123.123.123")
    r := spf.CheckHost(ip, "domain.com", "name@domain.com", "");
    // returns spf check result
    // "PASS" / "FAIL" / "SOFTFAIL" / "NEUTRAL" / "NONE" / "TEMPERROR" / "PERMERROR"

    // if you only need to retrive SPF record as string from DNS
    spfRecord, _ := spf.LookupSPF("domain.com")
}

Documentation

Index

Constants

View Source
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

View Source
var DNSServer = "8.8.8.8:53"

DNSServer global var to use for resolver in format <ip>:<port> By default it uses Google's 8.8.8.8:53 Misconfigured DNSServer will cause SPF checks to return TEMPERROR.

Functions

This section is empty.

Types

type Result

type Result string

Result of SPF check

func CheckHost

func CheckHost(ip net.IP, domain, sender, helo string) Result

CheckHost for SPF rules. 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 CheckHostSpf

func CheckHostSpf(ip net.IP, spf, domain, sender, helo string) Result

CheckHostSpf for SPF rules. ip - the IP address of the SMTP client that is emitting the mail, either IPv4 or IPv6. spf - the spf record to check against. 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 LookupSPF

func LookupSPF(domain string) (spf string, r Result)

LookupSPF returns spf txt record. if no records found or more than one record found, r value will be set accordingly to None or PermError. If dns lookup faild, r will be set to TempError.

func (Result) IsSet

func (r Result) IsSet() bool

IsSet returns true if Result var is set to some value

func (Result) String

func (r Result) String() string

String representation of Result type

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL