├── .DS_Store ├── .gitignore ├── LICENSE ├── assets └── demo.gif ├── cmd └── root.go ├── go.mod ├── go.sum ├── internal └── email │ ├── service.go │ └── verification.go ├── main.go ├── pkg └── helpers │ └── validation_helpers.go └── readme.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeeshanahmad0201/email_verification_tool/f5c1cc534ac41181625c75a1d893c662e2c8574d/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .history 2 | .env -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Zeeshan Ahmad 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /assets/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeeshanahmad0201/email_verification_tool/f5c1cc534ac41181625c75a1d893c662e2c8574d/assets/demo.gif -------------------------------------------------------------------------------- /cmd/root.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright © 2024 Zeeshan Ahmad 3 | */ 4 | package cmd 5 | 6 | import ( 7 | "os" 8 | 9 | "github.com/spf13/cobra" 10 | "github.com/zeeshanahmad0201/email_verification_tool/internal/email" 11 | ) 12 | 13 | const emailFlag = "email" 14 | 15 | // rootCmd represents the base command when called without any subcommands 16 | var rootCmd = &cobra.Command{ 17 | Use: "ev", 18 | Short: "", 19 | Long: `A powerful Golang-based tool for effortlessly scraping and tracking stock prices and financial ratios, with seamless data saving options.`, 20 | Run: func(cmd *cobra.Command, args []string) { 21 | 22 | if cmd.Flag(emailFlag).Changed { 23 | emailString := cmd.Flag(emailFlag).Value.String() 24 | err := email.VerifyEmail(emailString) 25 | if err != nil { 26 | cmd.Printf("Error: %s ❌\n", err.Error()) 27 | return 28 | } 29 | cmd.Println("\u2705Email address is valid\u2705") 30 | return 31 | } 32 | 33 | cmd.Help() 34 | }, 35 | } 36 | 37 | func Execute() { 38 | err := rootCmd.Execute() 39 | if err != nil { 40 | os.Exit(1) 41 | } 42 | } 43 | 44 | func init() { 45 | rootCmd.PersistentFlags().String("email", "", "Email address to verify") 46 | } 47 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/zeeshanahmad0201/email_verification_tool 2 | 3 | go 1.21.13 4 | 5 | require ( 6 | github.com/inconshreveable/mousetrap v1.1.0 // indirect 7 | github.com/spf13/cobra v1.8.1 // indirect 8 | github.com/spf13/pflag v1.0.5 // indirect 9 | ) 10 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= 2 | github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= 3 | github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= 4 | github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 5 | github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= 6 | github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= 7 | github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= 8 | github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 9 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 10 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 11 | -------------------------------------------------------------------------------- /internal/email/service.go: -------------------------------------------------------------------------------- 1 | package email 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/zeeshanahmad0201/email_verification_tool/pkg/helpers" 7 | ) 8 | 9 | func VerifyEmail(email string) error { 10 | 11 | if err := helpers.ValidateEmail(email); err != nil { 12 | return err 13 | } 14 | 15 | domain := email[strings.Index(email, "@")+1:] 16 | if err := CheckDomain(domain); err != nil { 17 | return err 18 | } 19 | 20 | return nil 21 | } 22 | -------------------------------------------------------------------------------- /internal/email/verification.go: -------------------------------------------------------------------------------- 1 | package email 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "strings" 7 | ) 8 | 9 | func CheckDomain(domain string) error { 10 | 11 | if err := validateDomain(domain); err != nil { 12 | return err 13 | } 14 | 15 | if err := validateSPFRecords(domain); err != nil { 16 | return err 17 | } 18 | 19 | if err := validateDMARCRecords(domain); err != nil { 20 | return err 21 | } 22 | 23 | fmt.Println("All checks passed successfully\U0001F973") 24 | return nil 25 | } 26 | 27 | func validateDomain(domain string) error { 28 | fmt.Println("Checking domain...") 29 | 30 | // Check if domain exists 31 | mxRecords, err := net.LookupMX(domain) 32 | if err != nil || len(mxRecords) == 0 { 33 | return fmt.Errorf("domain does not exist") 34 | } 35 | 36 | fmt.Println("Domain exists \u2714") 37 | return nil 38 | } 39 | 40 | func validateSPFRecords(domain string) error { 41 | fmt.Println("Checking domain's SPF records...") 42 | 43 | // Check if domain has a TXT record 44 | txtRecords, err := net.LookupTXT(domain) 45 | if err != nil || len(txtRecords) == 0 { 46 | return fmt.Errorf("domain does not have a TXT record") 47 | } 48 | 49 | hasSPF := false 50 | for _, txtRecord := range txtRecords { 51 | if strings.HasPrefix(txtRecord, "v=spf1") { 52 | // Domain has a valid SPF record 53 | hasSPF = true 54 | break 55 | } 56 | } 57 | 58 | if !hasSPF { 59 | return fmt.Errorf("domain does not have a valid SPF record") 60 | } else { 61 | fmt.Println("Domain has a valid SPF record \u2714") 62 | } 63 | 64 | return nil 65 | } 66 | 67 | func validateDMARCRecords(domain string) error { 68 | fmt.Println("Checking domain's DMARC records...") 69 | 70 | // Check if domain has a DMARC record 71 | dmarcRecords, err := net.LookupTXT("_dmarc." + domain) 72 | if err != nil || len(dmarcRecords) == 0 { 73 | return fmt.Errorf("domain does not have a DMARC record") 74 | } 75 | 76 | hasDMARC := false 77 | for _, dmarcRecord := range dmarcRecords { 78 | if strings.HasPrefix(dmarcRecord, "v=DMARC1") { 79 | // Domain has a valid DMARC record 80 | hasDMARC = true 81 | break 82 | } 83 | } 84 | 85 | if !hasDMARC { 86 | return fmt.Errorf("domain does not have a valid DMARC record") 87 | } else { 88 | fmt.Println("Domain has a valid DMARC record \u2714") 89 | } 90 | 91 | return nil 92 | } 93 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright © 2024 Zeeshan Ahmad 3 | */ 4 | package main 5 | 6 | import "github.com/zeeshanahmad0201/email_verification_tool/cmd" 7 | 8 | func main() { 9 | cmd.Execute() 10 | } 11 | -------------------------------------------------------------------------------- /pkg/helpers/validation_helpers.go: -------------------------------------------------------------------------------- 1 | package helpers 2 | 3 | import ( 4 | "fmt" 5 | "net/mail" 6 | "regexp" 7 | ) 8 | 9 | func ValidateEmail(email string) error { 10 | if email == "" { 11 | return fmt.Errorf("email address is required") 12 | } 13 | 14 | if _, err := mail.ParseAddress(email); err != nil { 15 | return fmt.Errorf("invalid email address") 16 | } 17 | 18 | emailRegex := `^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$` 19 | if ok, _ := regexp.MatchString(emailRegex, email); !ok { 20 | return fmt.Errorf("invalid email address") 21 | } 22 | 23 | return nil 24 | } 25 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Email Verification Tool 2 | 3 | ![Project Demo](assets/demo.gif) 4 | 5 | ## Introduction 6 | 7 | The Email Verification Tool is a lightweight and efficient GoLang-based utility designed to validate email addresses. It checks for basic syntax correctness, domain validity, and DNS records to ensure that the provided email address is likely to be valid. This tool does not include SMTP verification. 8 | 9 | ## Features 10 | 11 | - **Syntax Validation**: Ensures the email address adheres to standard email formatting rules. 12 | - **Domain Check**: Verifies if the domain part of the email address has valid MX (Mail Exchange) records. 13 | - **DNS Record Check**: Checks for the presence of TXT records, SPF, and DMARC records for domain verification. 14 | 15 | ## Installation 16 | 17 | To get started with the Email Verification Tool, you need to have Go installed on your system. Follow these steps to install and set up the tool: 18 | 19 | 1. **Clone the Repository**: 20 | 21 | ```bash 22 | git clone https://github.com/zeeshanahmad0201/email_verification_tool.git 23 | ``` 24 | 25 | 2. **Navigate to the Project Directory**: 26 | 27 | ```bash 28 | cd email_verification_tool 29 | ``` 30 | 31 | 3. **Install Dependencies**: 32 | 33 | ```bash 34 | go mod tidy 35 | ``` 36 | 37 | 4. **Build the Tool**: 38 | 39 | ```bash 40 | go build -o email_verification_tool 41 | ``` 42 | 43 | ## Usage 44 | 45 | You can use the Email Verification Tool directly from the command line. Here’s how to use it: 46 | 47 | 1. **Run the Tool**: 48 | 49 | ```bash 50 | ./ev --email= 51 | ``` 52 | 53 | 2. **Example**: 54 | 55 | ```bash 56 | ./ev --email=test@example.com 57 | ``` 58 | 59 | The tool will output whether the email address is likely valid or not based on the checks performed. 60 | 61 | ## Contributing 62 | 63 | We welcome contributions to enhance the Email Verification Tool. If you have any improvements, bug fixes, or new features, please follow these steps to contribute: 64 | 65 | 1. **Fork the Repository**: Create your own fork of the project. 66 | 2. **Create a Branch**: Create a new branch for your changes. 67 | 68 | ```bash 69 | git checkout -b feature-branch 70 | ``` 71 | 72 | 3. **Make Your Changes**: Implement your improvements or fixes. 73 | 4. **Commit Your Changes**: 74 | 75 | ```bash 76 | git add . 77 | git commit -m "Describe your changes" 78 | ``` 79 | 80 | 5. **Push to Your Fork**: 81 | 82 | ```bash 83 | git push origin feature-branch 84 | ``` 85 | 86 | 6. **Create a Pull Request**: Open a pull request from your fork to the main repository. 87 | 88 | ## License 89 | 90 | This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. 91 | 92 | ## Contact 93 | 94 | For any questions or inquiries, please reach out to: 95 | 96 | - **Email**: [xeeshanahmad0201@gmail.com](mailto:xeeshanahmad0201@gmail.com) 97 | --------------------------------------------------------------------------------