Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions backend/internal/utils/zerobounce.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package utils

import (
"encoding/json"
"fmt"
"net/http"
"os"
)

type ZeroBounceResponse struct {
Status string `json:"status"`
}

// VerifyEmailWithZeroBounce checks if an email address is valid using the ZeroBounce API
func VerifyEmailWithZeroBounce(email string) (string, error) {

apiKey := os.Getenv("ZEROBOUNCE_API_KEY")
if apiKey == "" {

return "", fmt.Errorf("ZeroBounce API key not set in environment variables")
}

url := fmt.Sprintf("https://api.zerobounce.net/v2/validate?email=%s&api_key=%s", email, apiKey)

resp, err := http.Get(url)
if err != nil {

return "", fmt.Errorf("failed to connect to ZeroBounce API: %v", err)
}

defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {

return "", fmt.Errorf("ZeroBounce API returned status: %s", resp.Status)
}

var result ZeroBounceResponse

if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {

return "", fmt.Errorf("error decoding ZeroBounce API response: %v", err)
}

return result.Status, nil
}
Loading