# Email Enrichment Bulk

## Overview

[Bulk Email Enrichment](https://tomba.io/bulks/email-enrichment) transforms basic email addresses into comprehensive contact profiles. Enhance your existing email lists with detailed personal and professional information about each contact.

### Key Features

- **Contact Profiling**: Add detailed information to existing email addresses
- **Professional Data**: Gather job titles, company information, and career details
- **Social Profiles**: Discover associated social media profiles
- **Bulk Processing**: Enrich up to 10,000 emails simultaneously
- **Data Accuracy**: High-quality, verified contact information
- **Export Options**: Multiple format options for enriched data

### How Email Enrichment Bulk Works

1. **Upload Email List**: Provide a list of email addresses to enrich
2. **Select Enrichment Fields**: Choose what additional data to gather
3. **Process Enrichment**: Launch the bulk enrichment operation
4. **Review Enhanced Profiles**: Examine the enriched contact data
5. **Export Results**: Download comprehensive contact profiles

### Limitations

- Each Bulk is limited to 10,000 email addresses
- Additional rows will be skipped
- Some special or unexpected characters may be deleted in the file
- Invalid email addresses won't be imported
- Duplicate email addresses won't be imported

## Go SDK Integration

### Installation

```bash
go get github.com/tomba-io/go
```

### Basic Setup

```go
package main

import (
    "fmt"
    "log"

    "github.com/tomba-io/go/tomba"
    "github.com/tomba-io/go/tomba/models"
)

func main() {
    // Initialize Tomba client
    client := tomba.NewTomba("your-api-key", "your-secret-key")

    // Your enrichment code here
}
```

### Creating an Enrichment Bulk Operation

```go
// Create enrichment bulk with email list
params := &models.BulkCreateParams{
    Name:     "Customer Email Enrichment - Q1 2024",
    List:     "john.doe@example.com\njane.smith@company.com\nuser@startup.io",
    Sources:  true,    // Include data sources
    Verify:   false,   // Skip email verification
    Notifie:  true,    // Send completion notification
}

// Create the bulk operation
response, err := client.CreateBulk(models.BulkTypeEnrich, params)
if err != nil {
    log.Fatal("Failed to create enrichment bulk:", err)
}

fmt.Printf("Created enrichment bulk with ID: %d\n", *response.Data.ID)
```

### Creating Enrichment Bulk with CSV File

```go
// Create enrichment bulk from CSV file
params := &models.BulkCreateParams{
    Name:      "Email List Enrichment - Marketing Database",
    Delimiter: ",",
    Column:    1,      // Email column (1-based index)
    Sources:   true,
    Verify:    false,
}

// Upload file and create bulk
response, err := client.CreateBulkWithFile(
    models.BulkTypeEnrich,
    params,
    "/path/to/email-list.csv",
)
if err != nil {
    log.Fatal("Failed to create bulk with file:", err)
}

bulkID := *response.Data.ID
fmt.Printf("Created bulk operation: %d\n", bulkID)
```

### Launching and Monitoring Enrichment

```go
// Launch the enrichment process
launchResponse, err := client.LaunchBulk(models.BulkTypeEnrich, bulkID)
if err != nil {
    log.Fatal("Failed to launch bulk:", err)
}

fmt.Println("Enrichment process started!")

// Monitor progress
for {
    progress, err := client.GetBulkProgress(models.BulkTypeEnrich, bulkID)
    if err != nil {
        log.Printf("Error checking progress: %v", err)
        break
    }

    fmt.Printf("Progress: %d%% (%d/%d processed)\n",
        progress.Progress,
        progress.Processed,
        progress.ProcessedEmail,
    )

    if progress.Status {
        fmt.Println("Enrichment completed!")
        break
    }

    // Wait 30 seconds before checking again
    time.Sleep(30 * time.Second)
}
```

### Retrieving and Exporting Results

```go
// Get bulk details
bulk, err := client.GetBulk(models.BulkTypeEnrich, bulkID)
if err != nil {
    log.Fatal("Failed to get bulk details:", err)
}

fmt.Printf("Bulk Status: %v\n", bulk.Data[0].Status)
fmt.Printf("Total Processed: %d\n", bulk.Data[0].Processed)

// Download enriched results
err = client.SaveBulkResults(
    models.BulkTypeEnrich,
    bulkID,
    "enriched-contacts.csv",
    "full", // Download type: "full", "valid", "not_found"
)
if err != nil {
    log.Fatal("Failed to download results:", err)
}

fmt.Println("Results saved to enriched-contacts.csv")
```

### Managing Enrichment Bulks

```go
// List all enrichment bulks
params := &models.BulkGetParams{
    Page:      1,
    Limit:     20,
    Direction: "desc",
    Filter:    "all", // "all", "archived"
}

bulks, err := client.GetAllEnrichBulks(params)
if err != nil {
    log.Fatal("Failed to get bulks:", err)
}

fmt.Printf("Found %d enrichment bulks\n", len(bulks.Data))

// Rename a bulk
renameParams := &models.BulkRenameParams{
    Name: "Updated Enrichment Name",
}

_, err = client.RenameBulk(models.BulkTypeEnrich, bulkID, renameParams)
if err != nil {
    log.Fatal("Failed to rename bulk:", err)
}

// Archive completed bulk
_, err = client.ArchiveBulk(models.BulkTypeEnrich, bulkID)
if err != nil {
    log.Fatal("Failed to archive bulk:", err)
}
```

### Advanced Example: Complete Enrichment Workflow

```go
func performEmailEnrichment(client *tomba.Tomba, csvFilePath string) error {
    // Step 1: Create bulk operation
    params := &models.BulkCreateParams{
        Name:      fmt.Sprintf("Email Enrichment - %s", time.Now().Format("2006-01-02")),
        Delimiter: ",",
        Column:    1,
        Sources:   true,
        Verify:    false,
        Notifie:   true,
    }

    response, err := client.CreateBulkWithFile(models.BulkTypeEnrich, params, csvFilePath)
    if err != nil {
        return fmt.Errorf("failed to create bulk: %w", err)
    }

    bulkID := *response.Data.ID
    log.Printf("Created enrichment bulk: %d", bulkID)

    // Step 2: Launch processing
    _, err = client.LaunchBulk(models.BulkTypeEnrich, bulkID)
    if err != nil {
        return fmt.Errorf("failed to launch bulk: %w", err)
    }

    // Step 3: Monitor progress with timeout
    timeout := time.After(30 * time.Minute)
    ticker := time.NewTicker(30 * time.Second)
    defer ticker.Stop()

    for {
        select {
        case <-timeout:
            return fmt.Errorf("enrichment timed out after 30 minutes")

        case <-ticker.C:
            progress, err := client.GetBulkProgress(models.BulkTypeEnrich, bulkID)
            if err != nil {
                log.Printf("Error checking progress: %v", err)
                continue
            }

            log.Printf("Enrichment progress: %d%%", progress.Progress)

            if progress.Status {
                // Step 4: Download results
                outputPath := fmt.Sprintf("enriched-%d.csv", bulkID)
                err = client.SaveBulkResults(models.BulkTypeEnrich, bulkID, outputPath, "full")
                if err != nil {
                    return fmt.Errorf("failed to save results: %w", err)
                }

                log.Printf("Enrichment completed! Results saved to: %s", outputPath)
                return nil
            }
        }
    }
}
```

## Best Practices

- **Valid Email Input**: Ensure all input emails are properly formatted
- **Data Privacy**: Comply with privacy regulations when enriching contact data
- **Regular Updates**: Refresh enriched data as contacts change roles
- **Segmentation**: Organize enriched contacts by relevant criteria
- **Quality Control**: Validate enriched data before using for outreach
- **Rate Limiting**: Monitor your API usage to avoid hitting limits
- **Error Handling**: Implement robust error handling for production applications
- **Progress Monitoring**: Use progress tracking for long-running enrichment operations
