
Security News
Bun 1.2.19 Adds Isolated Installs for Better Monorepo Support
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
github.com/mcnijman/go-emailaddress
go-emailaddress is a tiny Go library for finding, parsing and validating email addresses. This library is tested for Go v1.9 and above.
Note that there is no such thing as perfect email address validation other than sending an actual email (ie. with a confirmation token). This library however checks if the email format conforms to the spec and if the host (domain) is actually able to receive emails. You can also use this library to find emails in a byte array. This package was created as similar packages don't seem to be maintained anymore (ie contain bugs with pull requests still open), and/or use wrong local validation.
go get -u github.com/mcnijman/go-emailaddress
Parse and validate the email locally using RFC 5322 regex, note that when err == nil
it doesn't
necessarily mean the email address actually exists.
import "github.com/mcnijman/go-emailaddress"
email, err := emailaddress.Parse("foo@bar.com")
if err != nil {
fmt.Println("invalid email")
}
fmt.Println(email.LocalPart) // foo
fmt.Println(email.Domain) // bar.com
fmt.Println(email) // foo@bar.com
fmt.Println(email.String()) // foo@bar.com
Host validation will first attempt to resolve the domain and then verify if we can start a mail
transaction with the host. This is relatively slow as it will contact the host several times.
Note that when err == nil
it doesn't necessarily mean the email address actually exists.
import "github.com/mcnijman/go-emailaddress"
email, err := emailaddress.Parse("foo@bar.com")
if err != nil {
fmt.Println("invalid email")
}
err := email.ValidateHost()
if err != nil {
fmt.Println("invalid host")
}
Whether the public suffix is managed by the Internet Corporation for Assigned Names and Numbers. If not an error is returned and the public suffix is privately managed. For example, foo.org and foo.co.uk are ICANN domains, foo.dyndns.org and foo.blogspot.co.uk are private domains. More information on publix suffixes here.
import "github.com/mcnijman/go-emailaddress"
email, err := emailaddress.Parse("foo@bar.com")
if err != nil {
fmt.Println("invalid email")
}
err := email.ValidateIcanSuffix()
if err != nil {
fmt.Println("not an icann suffix")
}
This will look for emails in a byte array (ie text or an html response).
import "github.com/mcnijman/go-emailaddress"
text := []byte(`Send me an email at foo@bar.com or foo@domain.fakesuffix.`)
validateHost := false
emails := emailaddress.Find(text, validateHost)
for _, e := range emails {
fmt.Println(e)
}
// foo@bar.com
// foo@domain.fakesuffix
As RFC 5322 is really broad this method will likely match images and urls that contain the '@' character (ie. !--logo@2x.png). For more reliable results, you can use the following method.
import "github.com/mcnijman/go-emailaddress"
text := []byte(`Send me an email at foo@domain.com or foo@domain.fakesuffix.`)
validateHost := false
emails := emailaddress.FindWithIcannSuffix(text, validateHost)
for _, e := range emails {
fmt.Println(e)
}
// foo@bar.com
This library uses semantic versioning 2.0.0.
This library is distributed under the MIT license found in the LICENSE file.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
Security News
Popular npm packages like eslint-config-prettier were compromised after a phishing attack stole a maintainer’s token, spreading malicious updates.
Security News
/Research
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.