-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added go-dkim package and List-Unsubscribe header to the project (#54)
* added go-dkim package to the project * updated readme for dkim and unsubscribe examples * Removed privatekey because the parameter is not needed * requested changes for dkim and list-unsubscribe adding
- Loading branch information
1 parent
c20e8ef
commit 780823a
Showing
4 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,7 @@ import ( | |
"log" | ||
|
||
"github.com/xhit/go-simple-mail/v2" | ||
"github.com/toorop/go-dkim" | ||
) | ||
|
||
const htmlBody = `<html> | ||
|
@@ -109,6 +110,34 @@ const htmlBody = `<html> | |
</body> | ||
</html>` | ||
|
||
const privateKey = `-----BEGIN RSA PRIVATE KEY----- | ||
MIIEpAIBAAKCAQEAwGrscUxi9zEa9oMOJbS0kLVHZXNIW+EBjY7KFWIZSxuGAils | ||
wBVl+s5mMRrR5VlkyLQNulAdNemg6OSeB0R+2+8/lkHiMrimqQckZ5ig8slBoZhZ | ||
wUoL/ZkeQa1bacbdww5TuWkiVPD9kooT/+TZW1P/ugd6oYjpOI56ZjsXzJw5pz7r | ||
DiwcIJJaaDIqvvc5C4iW94GZjwtmP5pxhvBZ5D6Uzmh7Okvi6z4QCKzdJQLdVmC0 | ||
CMiFeh2FwqMkVpjZhNt3vtCo7Z51kwHVscel6vl51iQFq/laEzgzAWOUQ+ZEoQpL | ||
uTaUiYzzNyEdGEzZ2CjMMoO8RgtXnUo2qX2FDQIDAQABAoIBAHWKW3kycloSMyhX | ||
EnNSGeMz+bMtYwxNPMeebC/3xv+shoYXjAkiiTNWlfJ1MbbqjrhT1Pb1LYLbfqIF | ||
1csWum/bjHpbMLRPO++RH1nxUJA/BMqT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KesdSbolUilA8XQn/M113Lg8oA3gJXbAKqbTR/EgfUU | ||
kvYaR/rTFnivF4SL/P4k/gABQoJuFUtSKdouELqefXB+e94g/G++Bg== | ||
-----END RSA PRIVATE KEY-----` | ||
|
||
func main() { | ||
server := mail.NewSMTPClient() | ||
|
||
|
@@ -151,7 +180,8 @@ func main() { | |
email.SetFrom("From Example <[email protected]>"). | ||
AddTo("[email protected]"). | ||
AddCc("[email protected]"). | ||
SetSubject("New Go Email") | ||
SetSubject("New Go Email"). | ||
SetListUnsubscribe("<mailto:[email protected]?subject=https://example.com/unsubscribe>"). | ||
|
||
email.SetBody(mail.TextHTML, htmlBody) | ||
|
||
|
@@ -163,6 +193,21 @@ func main() { | |
// add inline | ||
email.Attach(&mail.File{FilePath: "/path/to/image.png", Name:"Gopher.png", Inline: true}) | ||
|
||
// you can add dkim signature to the email. | ||
// to add dkim, you need a private key already created one. | ||
if privateKey != "" { | ||
options := dkim.NewSigOptions() | ||
options.PrivateKey = []byte(privateKey) | ||
options.Domain = "example.com" | ||
options.Selector = "default" | ||
options.SignatureExpireIn = 3600 | ||
options.Headers = []string{"from", "date", "mime-version", "received", "received"} | ||
options.AddSignatureTimestamp = true | ||
options.Canonicalization = "relaxed/relaxed" | ||
|
||
email.SetDkim(options) | ||
} | ||
|
||
// always check error after send | ||
if email.Error != nil{ | ||
log.Fatal(email.Error) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
module github.com/xhit/go-simple-mail/v2 | ||
require ( | ||
github.com/toorop/go-dkim v0.0.0-20201103131630-e1cd1a0a5208 | ||
) | ||
|
||
go 1.13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
github.com/toorop/go-dkim v0.0.0-20201103131630-e1cd1a0a5208 h1:PM5hJF7HVfNWmCjMdEfbuOBNXSVF2cMFGgQTPdKCbwM= | ||
github.com/toorop/go-dkim v0.0.0-20201103131630-e1cd1a0a5208/go.mod h1:BzWtXXrXzZUvMacR0oF/fbDDgUPO8L36tDMmRAf14ns= | ||
github.com/xhit/go-simple-mail v2.2.2+incompatible h1:Hm2VGfLqiQJ/NnC8SYsrPOPyVYIlvP2kmnotP4RIV74= | ||
github.com/xhit/go-simple-mail v2.2.2+incompatible/go.mod h1:I8Ctg6vIJZ+Sv7k/22M6oeu/tbFumDY0uxBuuLbtU7Y= |