email

package module
v3.2.81 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: MIT Imports: 5 Imported by: 0

README

go-emailvalidation

Build GoDoc Go Report Card FOSSA Status

Purpose

Simple email validation package. Package supports either fast email validation via RFC compliant regex OR slower recursive DNS lookup. DNS validation checks for valid NS & MX records using the local DNS settings.

Supported versions

The current version is v3

Please import via go modules github.com/cameronnewman/go-emailvalidation/v3.

Usage

package main

import (
    "fmt"

    email "github.com/cameronnewman/go-emailvalidation/v3"
)

func main() {

    emailAddress := "John.Snow@gmaiiiiiiillllll.com"

    // Run all checks, including validating the format along with DNS lookups which
    // may be slower depending on your DNS server performance
    err := email.Validate(emailAddress)
    if err != nil {
        fmt.Println(err)
    }

    // Checks the format - this function performs no network
    // operations and is very fast
    err = email.ValidateFormat(emailAddress)
    if err != nil {
        fmt.Println(err)
    }

    // Checks domain NS & MX, along with format validation
    err = email.ValidateDomainRecords(emailAddress)
    if err != nil {
        fmt.Println(err)
    }

    // Normalize email address for storage
    address := email.Normalize(emailAddress)
    fmt.Println(address)
}

Issues

  • None

License

MIT Licensed

Documentation

Overview

Package email is a simple email validation package. Package validates email address string to RFC requirements and performs a DNS lookup for the MX records using the local DNS settings.

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrInvalidFormat is an error generated when the format is incorrect
	ErrInvalidFormat = errors.New("invalid email format")

	//ErrInvalidDomainNoNameServers is an error generated when the domain returns no Name Server records
	ErrInvalidDomainNoNameServers = errors.New("invalid email domain, unable to find name servers records")

	//ErrInvalidDomainNoMXRecords is an error generated when the domain returns no MX records
	ErrInvalidDomainNoMXRecords = errors.New("invalid email domain no mx records found")
)

Functions

func Normalize

func Normalize(email string) string

Normalize - Trim whitespaces, extra dots in the hostname and converts to Lowercase.

func Split

func Split(email string) (username string, domain string)

Split - Splits an email address into a username prefix and domain

func Validate

func Validate(email string) error

Validate - validates an email address via all options

func ValidateDomainRecords

func ValidateDomainRecords(email string) error

ValidateDomainRecords - validates an email address domain's NS and MX records via a DNS lookup

func ValidateFormat

func ValidateFormat(email string) error

ValidateFormat - validates an email address meets rfc 822 format via a regex

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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