• Stars
    star
    928
  • Rank 49,232 (Top 1.0 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

โœ… A Go library for email verification without sending any emails.

email-verifier

โœ‰๏ธ A Go library for email verification without sending any emails.

Build Status Godoc Coverage Status Go Report Card license

Features

  • Email Address Validation: validates if a string contains a valid email.
  • Email Verification Lookup via SMTP: performs an email verification on the passed email (catchAll detection enabled by default)
  • MX Validation: checks the DNS MX records for the given domain name
  • Misc Validation: including Free email provider check, Role account validation, Disposable emails address (DEA) validation
  • Email Reachability: checks how confident in sending an email to the address

Install

Use go get to install this package.

go get -u github.com/AfterShip/email-verifier

Usage

Basic usage

Use Verify method to verify an email address with different dimensions

package main

import (
	"fmt"
	
	emailverifier "github.com/AfterShip/email-verifier"
)

var (
	verifier = emailverifier.NewVerifier()
)


func main() {
	email := "[email protected]"

	ret, err := verifier.Verify(email)
	if err != nil {
		fmt.Println("verify email address failed, error is: ", err)
		return
	}
	if !ret.Syntax.Valid {
		fmt.Println("email address syntax is invalid")
		return
	}

	fmt.Println("email validation result", ret)
	/*
		result is:
		{
			"email":"[email protected]",
			"disposable":false,
			"reachable":"unknown",
			"role_account":false,
			"free":false,
			"syntax":{
			"username":"example",
				"domain":"exampledomain.org",
				"valid":true
			},
			"has_mx_records":true,
			"smtp":null,
			"gravatar":null
		}
	*/
}

Email verification Lookup

Use CheckSMTP to performs an email verification lookup via SMTP.

var (
    verifier = emailverifier.
        NewVerifier().
        EnableSMTPCheck()
)

func main() {

    domain := "domain.org"
    username := "username"
    ret, err := verifier.CheckSMTP(domain, username)
    if err != nil {
        fmt.Println("check smtp failed: ", err)
        return
    }

    fmt.Println("smtp validation result: ", ret)

}

If you want to disable catchAll checking, use the DisableCatchAllCheck() switch (in effect only when SMTP verification is enabled).

 verifier = emailverifier.
        NewVerifier().
        EnableSMTPCheck().
        DisableCatchAllCheck()

Note: because most of the ISPs block outgoing SMTP requests through port 25 to prevent email spamming, the module will not perform SMTP checking by default. You can initialize the verifier with EnableSMTPCheck() to enable such capability if port 25 is usable, or use a socks proxy to connect over SMTP

Use a SOCKS5 proxy to verify email

Support setting a SOCKS5 proxy to verify the email, proxyURI should be in the format: socks5://user:[email protected]:1080?timeout=5s

The protocol could be socks5, socks4 and socks4a.

var (
    verifier = emailverifier.
        NewVerifier().
        EnableSMTPCheck().
    	Proxy("socks5://user:[email protected]:1080?timeout=5s")
)

func main() {

    domain := "domain.org"
    username := "username"
    ret, err := verifier.CheckSMTP(domain, username)
    if err != nil {
        fmt.Println("check smtp failed: ", err)
        return
    }

    fmt.Println("smtp validation result: ", ret)

}

Misc Validation

To check if an email domain is disposable via IsDisposable

var (
    verifier = emailverifier.
        NewVerifier().
        EnableAutoUpdateDisposable()
)

func main() {
    domain := "domain.org"
    if verifier.IsDisposable(domain) {
        fmt.Printf("%s is a disposable domain\n", domain)
        return
    }
    fmt.Printf("%s is not a disposable domain\n", domain)
}

Note: It is possible to automatically update the disposable domains daily by initializing verifier with EnableAutoUpdateDisposable()

Suggestions for domain typo

Will check for typos in an email domain in addition to evaluating its validity. If we detect a possible typo, you will find a non-empty "suggestion" field in the validation result containing what we believe to be the correct domain. Also, you can use the SuggestDomain() method alone to check the domain for possible misspellings

func main() {
    domain := "gmai.com"
    suggestion := verifier.SuggestDomain(domain) 
    // suggestion should be `gmail.com`
    if suggestion != "" {
        fmt.Printf("domain %s is misspelled, right domain is %s. \n", domain, suggestion)
        return 
    }
    fmt.Printf("domain %s has no possible misspellings. \n", domain)
}

Note: When using the Verify() method, domain typo checking is not enabled by default, you can enable it in a verifier with EnableDomainSuggest()

For more detailed documentation, please check on godoc.org ๐Ÿ‘‰ email-verifier

API

We provide a simple self-hosted API server script for reference.

The API interface is very simple. All you need to do is to send a GET request with the following URL.

The email parameter would be the target email you want to verify.

https://{your_host}/v1/{email}/verification

Similar Libraries Comparison

email-verifier trumail check-if-email-exists freemail
Features ใ€ฐ๏ธ ใ€ฐ๏ธ ใ€ฐ๏ธ ใ€ฐ๏ธ
Disposable email address validation โœ… โœ…, but not available in free lib โœ… โœ…
Disposable address autoupdate โœ… ๐Ÿค” โŒ โŒ
Free email provider check โœ… โœ…, but not available in free lib โŒ โœ…
Role account validation โœ… โŒ โœ… โŒ
Syntax validation โœ… โœ… โœ… โŒ
Email reachability โœ… โœ… โœ… โŒ
DNS records validation โœ… โœ… โœ… โŒ
Email deliverability โœ… โœ… โœ… โŒ
Mailbox disabled โœ… โœ… โœ… โŒ
Full inbox โœ… โœ… โœ… โŒ
Host exists โœ… โœ… โœ… โŒ
Catch-all โœ… โœ… โœ… โŒ
Gravatar โœ… โœ…, but not available in free lib โŒ โŒ
Typo check โœ… โœ…, but not available in free lib โŒ โŒ
Use proxy to connect over SMTP โœ… โŒ โœ… โŒ
Honeyport dection ๐Ÿ”œ โŒ โŒ โŒ
Bounce email check ๐Ÿ”œ โŒ โŒ โŒ
Tech ใ€ฐ๏ธ ใ€ฐ๏ธ ใ€ฐ๏ธ ใ€ฐ๏ธ
Provide API โœ… โœ… โœ… โŒ
Free API โœ… โŒ โŒ โŒ
Language Go Go Rust JavaScript
Active maintain โœ… โŒ โœ… โœ…
High Performance โœ… โŒ โœ… โœ…

FAQ

The library hangs/takes a long time after 30 seconds when performing email verification lookup via SMTP

Most ISPs block outgoing SMTP requests through port 25 to prevent email spamming. email-verifier needs to have this port open to make a connection to the email's SMTP server. With the port being blocked, it is not possible to perform such checking, and it will instead hang until timeout error. Unfortunately, there is no easy workaround for this issue.

For more information, you may also visit this StackOverflow thread.

The output shows "connection refused" in the smtp.error field.

This error can also be due to SMTP ports being blocked by the ISP, see the above answer.

What does reachable: "unknown" means

This means that the server does not allow real-time verification of an email right now, or the email provider is a catch-all email server.

Credits

Contributing

For details on contributing to this repository, see the contributing guide.

License

This package is licensed under MIT license. See LICENSE for details.

More Repositories

1

phone

With a given country and phone number, validate and reformat the mobile phone number to the E.164 standard. The purpose of this is to allowย us to send SMS to mobile phones only.
TypeScript
759
star
2

SaaS

List of SaaS that we are using
123
star
3

aftership-sdk-php

The PHP SDK of AfterShip API
PHP
64
star
4

aftership-sdk-nodejs

The node.js SDK of AfterShip API
JavaScript
61
star
5

aftership-sdk-python

The python SDK of AfterShip API
Python
48
star
6

clickhouse-sql-parser

ClickHouse SQL Parser writing in Go
Go
43
star
7

challenge

Different challenges, try them all if you like!
40
star
8

eslint-config-aftership

The coding guideline for AfterShip's node.js projects
JavaScript
38
star
9

aftership-sdk-ruby

The ruby gem SDK of AfterShip API
Ruby
32
star
10

aftership-apps-woocommerce

Add tracking number and carrier name, insert Track Button to order history page, and auto import tracking numbers from WooCommerce.
PHP
20
star
11

company-intro

We like to show case our engineering culture, from hiring to PR marketing.
JavaScript
19
star
12

deprecated-koa-newrelic

Koa middleware to allow Newrelic monitor Koa applications like Express
JavaScript
18
star
13

swagger-ajv

Old name: koa-swagger-ajv
JavaScript
16
star
14

aftership-sdk-net

The .NET SDK of AfterShip API
C#
13
star
15

aftership-sdk-java

The Java SDK of AfterShip API
Java
13
star
16

deprecated-apps-spree

Spree Extension for AfterShip
Ruby
13
star
17

bsw

JavaScript
11
star
18

aftership-sdk-go

Golang SDK for Aftership API
Go
10
star
19

rate-limiter

Redis rate limiter for Node.js
JavaScript
10
star
20

apps-opencart

PHP
10
star
21

aftership-sdk-android

The Android SDK of AfterShip API
Java
7
star
22

bigquery-streamer

JavaScript
7
star
23

demo-k8s-nodejs

JavaScript
6
star
24

deprecated-demo-cloudflare-workers

5
star
25

aftership-apps-prestashop

Auto import tracking numbers and order info from PrestaShop store every 3 hours.
PHP
4
star
26

deprecated-newrelic.aftershipdemo.com

This is demo site for NewRelic APM testing event on 2019-02-23
JavaScript
4
star
27

deprecated-demo-beanstalkd

Demo Beanstalkd
JavaScript
3
star
28

deprecated-demo-newrelic

JavaScript
2
star
29

deprecated-spot-cluster

JavaScript
2
star
30

deprecated-demo_streamer2bigquery

The demo streaming data from redis to bigquery
JavaScript
2
star
31

demo-bdd-test-workshop

A workshop for bdd test coding by Nodejs
JavaScript
1
star
32

node-tmfy

JavaScript
1
star
33

ga.aftershipdemo.com

This is demo site for GA AB Testing event on 2018-01-19
HTML
1
star
34

techblog.aftership.com

HTML
1
star