> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sanitizeemail.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Clean Email List

> Process and clean an uploaded email list file with comprehensive validation options

This endpoint processes and cleans an uploaded email list file with comprehensive validation options. It requires a previously uploaded file from the [File Upload](/api-reference/endpoint/file_upload) endpoint.

## How it Works

<Steps>
  <Step title="Upload File First">
    Use the [File Upload endpoint](/api-reference/endpoint/file_upload) to
    upload your CSV or XLSX file and obtain the `file_id` and `file` URL
  </Step>

  <Step title="Configure Cleaning Options">
    Set your desired validation options (syntax, DMARC, SMTP, MX records)
  </Step>

  <Step title="Submit Cleaning Job">
    Send the cleaning request with the file reference and options
  </Step>

  <Step title="Monitor Progress">
    Use the returned `job_id` to track the cleaning progress
  </Step>
</Steps>

## Prerequisites

<Note>
  **File Upload Required**: You must first upload a file using the
  `/v1/api/filesupload/` endpoint to obtain the required `file_id` and `file`
  URL parameters.
</Note>

## Validation Options

The cleaning process supports multiple validation levels:

* **validate\_syntax**: Checks email format and structure
* **check\_dmarc**: Validates DMARC policy records
* **validate\_smtp**: Performs SMTP server validation
* **validate\_mx**: Checks MX record existence

<Tip>
  **Comprehensive Cleaning**: Enable all validation options for the most
  thorough email list cleaning, though this will consume more credits and take
  longer to process.
</Tip>

## Example Workflow

```json theme={null}
// 1. First upload a file
POST /v1/api/filesupload/
// Response includes: { "id": 739, "file": "https://s3.../file.csv" }

// 2. Then clean the uploaded file
POST /v1/api/cleanemail/
{
  "file_id": 739,
  "file": "https://s3.us-east-1.amazonaws.com/sanitizeemail/email_validation_files/Book_Sheet1_e5FL41X.csv",
  "user": 100,
  "list_name": "Customer List - Cleaned",
  "options": {
    "validate_syntax": true,
    "check_dmarc": true,
    "validate_smtp": true,
    "validate_mx": true
  }
}
```

<Warning>
  **Credits Consumption**: The cleaning process consumes credits based on the
  number of emails and validation options selected. More comprehensive
  validation uses more credits.
</Warning>


## OpenAPI

````yaml POST /v1/api/cleanemail/
openapi: 3.1.0
info:
  title: Sanitize-Email API (v1)
  description: Welcome to the Sanitize-Email API Documentation
  license:
    name: Proprietary License
  version: 1.0.0
servers:
  - url: https://base.sanitizeemail.com
security:
  - apiKeyAuth: []
paths:
  /v1/api/cleanemail/:
    post:
      tags:
        - Email Cleaning
      summary: Clean Email List
      description: >-
        Process and clean an uploaded email list file with comprehensive
        validation options
      requestBody:
        description: Email list cleaning request payload
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CleanEmailRequest'
      responses:
        '200':
          description: Email cleaning job initiated successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CleanEmailResponse'
        '400':
          description: Bad request - Invalid payload or file reference
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/RateLimitExceeded'
components:
  schemas:
    CleanEmailRequest:
      type: object
      required:
        - file_id
        - file
        - user
        - list_name
      properties:
        file_id:
          type: integer
          description: ID of the uploaded file (obtained from file upload response)
          example: 739
        list_name:
          type: string
          description: Name for the cleaned email list
          example: Customer List - Cleaned
        options:
          type: object
          description: Validation and cleaning options
          properties:
            validate_syntax:
              type: boolean
              description: Whether to validate email syntax
              default: true
            check_dmarc:
              type: boolean
              description: Whether to check DMARC records
              default: true
            validate_smtp:
              type: boolean
              description: Whether to perform SMTP validation
              default: true
            validate_mx:
              type: boolean
              description: Whether to validate MX records
              default: true
    CleanEmailResponse:
      type: object
      properties:
        job_id:
          type: string
          description: Unique identifier for the cleaning job
        status:
          type: string
          enum:
            - queued
            - processing
            - completed
            - failed
          description: Current status of the cleaning job
        list_name:
          type: string
          description: Name of the email list being cleaned
        file_id:
          type: integer
          description: ID of the source file
        estimated_completion_time:
          type: string
          format: date-time
          description: Estimated completion time for the cleaning job
        options_applied:
          type: object
          description: Validation options that will be applied
          properties:
            validate_syntax:
              type: boolean
            check_dmarc:
              type: boolean
            validate_smtp:
              type: boolean
            validate_mx:
              type: boolean
        total_emails:
          type: integer
          description: Total number of emails to be processed
        credits_required:
          type: integer
          description: Number of credits required for this cleaning job
    Error:
      required:
        - error
        - message
      type: object
      properties:
        error:
          type: integer
          format: int32
        message:
          type: string
  responses:
    Unauthorized:
      description: Unauthorized - Invalid or missing API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    NotFound:
      description: File not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    RateLimitExceeded:
      description: Rate limit exceeded
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: X-API-KEY
      description: API key for authentication

````