Skip to content

Commit

Permalink
fix configs
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbr0wn committed Aug 17, 2024
1 parent 8fdef33 commit 3bad55f
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 63 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ go.work.sum

.idea/
mailsherpa
*.csv
*.txt
24 changes: 24 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Justfile for MailSherpa CLI

version := `git describe --tags --always`
ldflags := "-X github.com/customeros/mailsherpa/internal/cmd.version=" + version

build-macos:
@echo "Building MailSherpa CLI for MacOS..."
GOOS=darwin go build -ldflags "{{ldflags}}" -o mailsherpa-macos

build-linux-amd64:
@echo "Building MailSherpa CLI for Linux AMD64..."
GOOS=linux GOARCH=amd64 go build -ldflags "{{ldflags}}" -o mailsherpa-linux-amd64

build-linux-arm64:
@echo "Building MailSherpa CLI for Linux ARM64..."
GOOS=linux GOARCH=arm64 go build -ldflags "{{ldflags}}" -o mailsherpa-linux-arm64

build: build-macos build-linux-amd64 build-linux-arm64

clean:
rm -f mailsherpa-linux-arm64 mailsherpa-linux-amd64 mailsherpa-macos

test:
go test ./...
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,34 @@ This is open-source, but we also offer a hosted API that's simple to use. If you

<br />

## Get Started
## Quickstart

1. Download the appropriate CLI tarball for your OS:

```
wget mailsherpa.sh/mailsherpa-linux-arm64.tar.gz
wget mailsherpa.sh/mailsherpa-linux-amd64.tar.gz
wget mailsherpa.sh/mailsherpa-macos.tar.gz
```

2. Extract the binary:

```
tar -xzf filename.tar.gz
```

3. Set the `MAIL_SERVER_DOMAIN` environment variable. See the `Mail Server setup guide` section below for more details:

```
export MAIL_SERVER_DOMAIN=example.com
```

4. Test to make sure everything is working

```
./mailsherpa version
```

## Mail Server setup guide

You might be asking why you need to setup a mail server...
4 changes: 3 additions & 1 deletion internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/customeros/mailsherpa/mailvalidate"
)

var version = "dev"

func PrintUsage() {
fmt.Println("Usage: mailsherpa <command> [arguments]")
fmt.Println("Commands:")
Expand Down Expand Up @@ -59,7 +61,7 @@ func VerifyEmail(email string) {
}

func Version() {
fmt.Println("MailSherpa", run.Version)
fmt.Printf("MailSherpa %s\n", version)
}

func printOutput(response interface{}) {
Expand Down
37 changes: 2 additions & 35 deletions internal/mailserver/mailserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"strings"
"time"

"golang.org/x/net/proxy"

"github.com/customeros/mailsherpa/internal/dns"
)

Expand All @@ -30,7 +28,7 @@ type ProxySetup struct {
Password string
}

func VerifyEmailAddress(email, fromDomain, fromEmail string, proxy ProxySetup) (bool, SMPTValidation, error) {
func VerifyEmailAddress(email, fromDomain, fromEmail string) (bool, SMPTValidation, error) {
results := SMPTValidation{}
var isVerified bool

Expand All @@ -46,12 +44,7 @@ func VerifyEmailAddress(email, fromDomain, fromEmail string, proxy ProxySetup) (
var conn net.Conn
var client *bufio.Reader

if proxy.Enable {
fmt.Println("Enabling proxy...")
conn, client, err = connectToSMTPviaProxy(mxServers[0], proxy.Address, proxy.Username, proxy.Password)
} else {
conn, client, err = connectToSMTP(mxServers[0])
}
conn, client, err = connectToSMTP(mxServers[0])
if err != nil {
return false, results, err
}
Expand Down Expand Up @@ -88,32 +81,6 @@ func connectToSMTP(mxServer string) (net.Conn, *bufio.Reader, error) {
return conn, client, nil
}

func connectToSMTPviaProxy(mxServer, proxyAddress, proxyUsername, proxyPassword string) (net.Conn, *bufio.Reader, error) {
auth := &proxy.Auth{
User: proxyUsername,
Password: proxyPassword,
}

dialer, err := proxy.SOCKS5("tcp", proxyAddress, auth, proxy.Direct)
if err != nil {
return nil, nil, fmt.Errorf("Failed to connect proxy dialer: %w", err)
}

conn, err := dialer.Dial("tcp", mxServer+":25")
if err != nil {
return nil, nil, fmt.Errorf("Failed to connect to SMTP server via proxy: %w", err)
}

err = conn.SetDeadline(time.Now().Add(30 * time.Second))
if err != nil {
conn.Close()
return nil, nil, fmt.Errorf("Failed to set connection deadline: %w", err)
}

client := bufio.NewReader(conn)
return conn, client, nil
}

func readSMTPgreeting(smtpClient *bufio.Reader) error {
for {
line, err := smtpClient.ReadString('\n')
Expand Down
23 changes: 10 additions & 13 deletions internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@ package run

import (
"fmt"
"os"

"github.com/customeros/mailsherpa/mailvalidate"
)

const (
fromDomain = "gmail.com"
validateFreeAccounts = true
validateRoleMailboxes = true
Version = "0.0.10"
)

type VerifyEmailResponse struct {
Email string
IsDeliverable bool
Expand Down Expand Up @@ -43,14 +37,17 @@ type Smtp struct {

func BuildRequest(email string) mailvalidate.EmailValidationRequest {
firstname, lastname := mailvalidate.GenerateNames()
fromDomain, exists := os.LookupEnv("MAIL_SERVER_DOMAIN")
if !exists {
fmt.Println("MAIL_SERVER_DOMAIN environment variable not set")
os.Exit(1)
}

request := mailvalidate.EmailValidationRequest{
Email: email,
FromDomain: fromDomain,
FromEmail: fmt.Sprintf("%s.%s@%s", firstname, lastname, fromDomain),
CatchAllTestUser: mailvalidate.GenerateCatchAllUsername(),
ValidateFreeAccounts: validateFreeAccounts,
ValidateRoleAccounts: validateRoleMailboxes,
Email: email,
FromDomain: fromDomain,
FromEmail: fmt.Sprintf("%s.%s@%s", firstname, lastname, fromDomain),
CatchAllTestUser: mailvalidate.GenerateCatchAllUsername(),
}
return request
}
Expand Down
17 changes: 4 additions & 13 deletions mailvalidate/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ import (
)

type EmailValidationRequest struct {
Email string
FromDomain string
FromEmail string
CatchAllTestUser string
ValidateFreeAccounts bool
ValidateRoleAccounts bool
Proxy mailserver.ProxySetup
Email string
FromDomain string
FromEmail string
CatchAllTestUser string
}

type DomainValidation struct {
Expand Down Expand Up @@ -144,15 +141,10 @@ func ValidateEmail(validationRequest EmailValidationRequest) (EmailValidation, e
}
results.IsRoleAccount = isRoleAccount

if isRoleAccount && !validationRequest.ValidateRoleAccounts {
return results, nil
}

isVerified, smtpValidation, err := mailserver.VerifyEmailAddress(
validationRequest.Email,
validationRequest.FromDomain,
validationRequest.FromEmail,
validationRequest.Proxy,
)
if err != nil {
return results, errors.Wrap(err, "Error validating email via SMTP")
Expand Down Expand Up @@ -243,7 +235,6 @@ func catchAllTest(validationRequest EmailValidationRequest) (bool, mailserver.SM
catchAllEmail,
validationRequest.FromDomain,
validationRequest.FromEmail,
validationRequest.Proxy,
)
if err != nil {
log.Printf("Error validating email via SMTP: %v", err)
Expand Down

0 comments on commit 3bad55f

Please sign in to comment.