Skip to content

Commit ae25572

Browse files
committed
added bulk email validation through excel and cli tool
Signed-off-by: adarsh-jaiss <[email protected]>
1 parent 7304c0c commit ae25572

File tree

9 files changed

+566
-3
lines changed

9 files changed

+566
-3
lines changed

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
Mailify is a Go package for validating email addresses by checking their format, verifying the existence of MX records for the domain, and attempting to connect to the mail servers using SMTP.
44

5+
## CLI
6+
7+
You can use this as a cli tool on your local machine by installing the mailify cli tool
8+
9+
```bash
10+
go install github.com/yourusername/mailify-cli@latest
11+
```
12+
13+
For more details, checkout [CLI DOCS](https://github.com/Adarsh-jaiss/mailify/blob/main/cli/README.md)
14+
15+
516
## Installation
617

718
To install the package, run:
@@ -61,5 +72,19 @@ if err != nil {
6172
fmt.Println("Mail servers:", mailServers)
6273
```
6374

75+
76+
### Validate all the email addresses in an Excel file
77+
78+
This section demonstrates how to validate all email addresses in an Excel file using the `ProcessAndValidateEmailsViaExcel` method. The method takes the path to the Excel file and the sender's email as parameters. If there is an error during the processing of the file, it will print an error message and terminate the execution.
79+
80+
Example usage:
81+
82+
```go
83+
err = client.ProcessAndValidateEmailsViaExcel("emails.xlsx",client.SenderEmail)
84+
if err!= nil {
85+
fmt.Printf("Error processing file: %v\n", err)
86+
return
87+
}
88+
```
6489
### Example
65-
Here is a complete example demonstrating how to use the package : [check examples](https://github.com/Adarsh-jaiss/mailify/blob/main/cmd/mailify/main.go)
90+
Here is a complete example demonstrating how to use the package : [check examples](https://github.com/Adarsh-jaiss/mailify/blob/main/example/main.go)

cli/README.md

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
# Mailify CLI
2+
3+
Mailify CLI is a powerful command-line tool for email validation and mail server information retrieval. Built on top of the [mailify](https://github.com/adarsh-jaiss/mailify) library, it provides an easy-to-use interface for validating email addresses and getting mail server details.
4+
5+
## Features
6+
7+
- Single email address validation
8+
- Bulk email validation using Excel files
9+
- Mail server lookup for domains
10+
- Mail server lookup for email addresses
11+
- Simple flag-based interface
12+
13+
## Installation
14+
15+
### Using Go
16+
17+
```bash
18+
go install github.com/yourusername/mailify-cli@latest
19+
```
20+
21+
### Using Binary Releases
22+
23+
Download the latest binary for your platform from the [releases page](https://github.com/yourusername/mailify-cli/releases).
24+
25+
## Usage
26+
27+
The CLI tool uses a flag-based interface where all operations are performed using the main `mailify` command with different flags.
28+
29+
### Required Flag
30+
31+
- `-s, --sender`: Sender email address (required for all operations)
32+
33+
### Operation Flags
34+
35+
You can use one of the following operation flags per command:
36+
37+
- `-v, --validate`: Validate a single email address
38+
- `-e, --excel`: Process and validate emails from an Excel file
39+
- `-d, --domain`: Get mail servers for a domain
40+
- `-r, --receipient`: Get mail servers for a recipient email
41+
42+
### Examples
43+
44+
1. **Validate a single email address**
45+
```bash
46+
47+
```
48+
49+
2. **Bulk validate emails from Excel file**
50+
```bash
51+
mailify -s [email protected] -e emails.xlsx
52+
```
53+
54+
3. **Get mail servers for a domain**
55+
```bash
56+
mailify -s [email protected] -d example.com
57+
```
58+
59+
4. **Get mail servers for an email address**
60+
```bash
61+
62+
```
63+
64+
### Help
65+
66+
```bash
67+
mailify --help
68+
```
69+
70+
## Development Setup
71+
72+
1. Clone the repository
73+
```bash
74+
git clone https://github.com/yourusername/mailify-cli.git
75+
cd mailify-cli
76+
```
77+
78+
2. Install dependencies
79+
```bash
80+
go mod download
81+
```
82+
83+
3. Build the project
84+
```bash
85+
go build -o mailify
86+
```
87+
88+
## Release Process
89+
90+
### Using GoReleaser
91+
92+
1. Install GoReleaser:
93+
```bash
94+
brew install goreleaser
95+
```
96+
97+
2. Create `.goreleaser.yml`:
98+
```yaml
99+
before:
100+
hooks:
101+
- go mod tidy
102+
builds:
103+
- env:
104+
- CGO_ENABLED=0
105+
goos:
106+
- linux
107+
- windows
108+
- darwin
109+
goarch:
110+
- amd64
111+
- arm64
112+
binary: mailify
113+
archives:
114+
- replacements:
115+
darwin: Darwin
116+
linux: Linux
117+
windows: Windows
118+
amd64: x86_64
119+
checksum:
120+
name_template: 'checksums.txt'
121+
snapshot:
122+
name_template: "{{ incpatch .Version }}-next"
123+
changelog:
124+
sort: asc
125+
filters:
126+
exclude:
127+
- '^docs:'
128+
- '^test:'
129+
```
130+
131+
3. Release Steps:
132+
```bash
133+
# Create and push a new tag
134+
git tag -a v0.1.0 -m "First release"
135+
git push origin v0.1.0
136+
137+
# Set GitHub token
138+
export GITHUB_TOKEN="your-github-token"
139+
140+
# Create release
141+
goreleaser release --rm-dist
142+
```
143+
144+
## Excel File Format
145+
146+
When using the `-e, --excel` flag, your Excel file should:
147+
- Have a column containing email addresses
148+
- Be in `.xlsx` format
149+
- The tool will create a new column with validation results
150+
151+
## Error Handling
152+
153+
- If no operation flag is specified, the tool will show an error message
154+
- All operations will return meaningful error messages if something goes wrong
155+
- The tool validates inputs before processing
156+
157+
## Contributing
158+
159+
Contributions are welcome! Please feel free to submit a Pull Request.
160+
161+
## License
162+
163+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
164+
165+
## Support
166+
167+
If you encounter any issues or have questions, please:
168+
1. Check the [GitHub Issues](https://github.com/yourusername/mailify-cli/issues)
169+
2. Create a new issue if your problem isn't already reported

cli/cmd/root.go

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/adarsh-jaiss/mailify"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
// senderEmail represents the email address of the sender.
12+
var (
13+
senderEmail string
14+
client *mailify.Client
15+
emailToCheck string
16+
excelFile string
17+
domain string
18+
receipientEmail string
19+
)
20+
21+
// rootCmd represents the base command for the Mailify CLI tool
22+
// rootCmd represents the base command when called without any subcommands.
23+
// It provides functionality to validate email addresses and get mail server information.
24+
//
25+
// Usage:
26+
// mailify [flags]
27+
//
28+
// Flags:
29+
// -e, --email string Email address to validate
30+
// -x, --excel string Path to Excel file for bulk email validation
31+
// -d, --domain string Domain to get mail servers for
32+
// -r, --receipient string Email address to get mail servers for
33+
//
34+
// Examples:
35+
// # Validate a single email address
36+
// mailify --email [email protected]
37+
//
38+
// # Bulk validate emails from an Excel file
39+
// mailify --excel emails.xlsx
40+
//
41+
// # Get mail servers for a domain
42+
// mailify --domain example.com
43+
//
44+
// # Get mail servers for an email address
45+
// mailify --receipient [email protected]
46+
//
47+
// If no flags are provided, an error will be returned indicating that no operation was specified.
48+
var rootCmd = &cobra.Command{
49+
Use: "mailify",
50+
Short: "Mailify is a CLI tool for email validation and server information",
51+
Long: `Mailify CLI provides functionality to validate email addresses and get mail server information.
52+
It can process single email addresses or bulk validate emails from Excel files.`,
53+
RunE: func(cmd *cobra.Command, args []string) error {
54+
// Initialize client
55+
var err error
56+
client, err = mailify.NewClient(senderEmail)
57+
if err != nil {
58+
return fmt.Errorf("failed to create mailify client: %v", err)
59+
}
60+
61+
// Handle single email validation
62+
if emailToCheck != "" {
63+
result, err := client.ValidateEmail(emailToCheck)
64+
if err != nil {
65+
return fmt.Errorf("failed to validate email: %v", err)
66+
}
67+
fmt.Println(client.FormatValidationResult(emailToCheck, result))
68+
}
69+
70+
// Handle bulk validation from Excel
71+
if excelFile != "" {
72+
err := client.ProcessAndValidateEmailsViaExcel(excelFile, client.SenderEmail)
73+
if err != nil {
74+
return fmt.Errorf("failed to process Excel file: %v", err)
75+
}
76+
fmt.Println("Successfully processed and validated emails in", excelFile)
77+
}
78+
79+
// Handle domain mail servers
80+
if domain != "" {
81+
servers, err := client.GetMailServers(domain)
82+
if err != nil {
83+
return fmt.Errorf("failed to get mail servers: %v", err)
84+
}
85+
fmt.Println("Mail servers for", domain+":")
86+
for _, server := range servers {
87+
fmt.Println("-", server)
88+
}
89+
}
90+
91+
// Handle email mail servers
92+
if receipientEmail != "" {
93+
servers, err := client.GetMailServersFromReceipientEmail(receipientEmail)
94+
if err != nil {
95+
return fmt.Errorf("failed to get mail servers: %v", err)
96+
}
97+
fmt.Println("Mail servers for", receipientEmail+":")
98+
for _, server := range servers {
99+
fmt.Println("-", server)
100+
}
101+
}
102+
103+
// Check if no flags were provided
104+
if emailToCheck == "" && excelFile == "" && domain == "" && receipientEmail == "" {
105+
return fmt.Errorf("no operation specified. Use --help to see available flags")
106+
}
107+
108+
return nil
109+
},
110+
}
111+
112+
// Execute runs the root command and handles any errors that occur during its execution.
113+
// If an error is encountered, it prints the error message and exits the program with a status code of 1.
114+
func Execute() {
115+
if err := rootCmd.Execute(); err != nil {
116+
fmt.Println(err)
117+
os.Exit(1)
118+
}
119+
}
120+
121+
// init initializes the command-line flags for the root command.
122+
// It sets up the following flags:
123+
// - sender: Required flag for specifying the sender email address.
124+
// - validate: Optional flag for validating a single email address.
125+
// - excel: Optional flag for processing and validating emails from an Excel file.
126+
// - domain: Optional flag for getting mail servers for a domain.
127+
// - receipient: Optional flag for getting mail servers for a recipient email.
128+
func init() {
129+
// Required sender email flag
130+
rootCmd.Flags().StringVarP(&senderEmail, "sender", "s", "", "Sender email address (required)")
131+
rootCmd.MarkFlagRequired("sender")
132+
133+
// Operation flags
134+
rootCmd.Flags().StringVarP(&emailToCheck, "validate", "v", "", "Validate a single email address")
135+
rootCmd.Flags().StringVarP(&excelFile, "excel", "e", "", "Process and validate emails from an Excel file")
136+
rootCmd.Flags().StringVarP(&domain, "domain", "d", "", "Get mail servers for a domain")
137+
rootCmd.Flags().StringVarP(&receipientEmail, "receipient", "r", "", "Get mail servers for a receipient email")
138+
}

cli/mailify

11.7 MB
Binary file not shown.

cli/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package main
2+
3+
import (
4+
"github.com/adarsh-jaiss/mailify/cli/cmd"
5+
)
6+
7+
func main() {
8+
cmd.Execute()
9+
}

cmd/mailify/main.go renamed to example/mailify/main.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import (
88
)
99

1010
func main() {
11-
// Create a new mailguard client
11+
// Create a new mailify client
1212
senderEmail := "[email protected]"
1313
receipientEmail := "[email protected]"
1414

1515
client, err := mailify.NewClient(senderEmail)
1616
if err != nil {
17-
log.Fatalf("Failed to create mailguard client: %v", err)
17+
log.Fatalf("Failed to create mailify client: %v", err)
1818
}
1919

2020
// Get mail servers for a domain
@@ -39,4 +39,11 @@ func main() {
3939

4040
fmt.Println("Validation result:", client.FormatValidationResult(receipientEmail,result))
4141

42+
// Validate all the email address in an Excel file, creates a new column with the validation result
43+
err = client.ProcessAndValidateEmailsViaExcel("emails.xlsx",client.SenderEmail)
44+
if err!= nil {
45+
fmt.Printf("Error processing file: %v\n", err)
46+
return
47+
}
48+
4249
}

0 commit comments

Comments
 (0)