Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Latest commit

 

History

History
61 lines (44 loc) · 1.52 KB

README.md

File metadata and controls

61 lines (44 loc) · 1.52 KB

go-dkim

GoDoc builds.sr.ht status codecov

A Go library to create and verify DKIM signatures.

Note: this repository has been migrated to https://github.com/emersion/go-msgauth

Usage

Sign

r := strings.NewReader(mailString)

options := &SignOptions{
	Domain: "example.org",
	Selector: "brisbane",
	Signer: privateKey,
}

var b bytes.Buffer
if err := dkim.Sign(&b, r, options); err != nil {
	log.Fatal(err)
}

Verify

r := strings.NewReader(mailString)

verifications, err := dkim.Verify(r)
if err != nil {
	log.Fatal(err)
}

for _, v := range verifications {
	if v.Err == nil {
		log.Println("Valid signature for:", v.Domain)
	} else {
		log.Println("Invalid signature for:", v.Domain, v.Err)
	}
}

FAQ

Why can't I verify a mail.Message directly? A mail.Message header is already parsed, and whitespace characters (especially continuation lines) are removed. Thus, the signature computed from the parsed header is not the same as the one computed from the raw header.

How can I publish my public key? You have to add a TXT record to your DNS zone. See RFC 6376 appendix C.

License

MIT