Skip to content

Email Address Validation

The validate command checks if email addresses are likely deliverable before you send emails. This helps prevent bounce-backs and improves email deliverability.

Overview

Email validation performs several checks to determine if an email address can receive messages:

  1. Syntax validation - Checks if the email format is valid (RFC 5322 compliant)
  2. Domain validation - Verifies the domain exists via DNS lookup
  3. MX record check - Confirms the domain has mail server records configured
  4. SMTP verification (optional) - Attempts to verify with the mail server directly

Basic Usage

bash
# Validate a single email address
mailos validate [email protected]

# Validate multiple email addresses
mailos validate [email protected] [email protected] [email protected]

# Using the --email flag (can be repeated)
mailos validate --email [email protected] --email [email protected]

Command-Line Flags

Basic Options

FlagShortTypeDefaultDescriptionExample
--email-e[]stringEmail address(es) to validate (can be repeated)mailos validate --email value

Advanced Options

FlagShortTypeDefaultDescriptionExample
--fullboolfalsePerform full validation including SMTP check (slower)mailos validate --full
--quickboolfalsePerform quick validation (syntax + MX only)mailos validate --quick

Output Options

FlagShortTypeDefaultDescriptionExample
--jsonboolfalseOutput results as JSONmailos validate --json
--verbose-vboolfalseShow detailed validation informationmailos validate --verbose

Command Flags

FlagShortTypeDefaultDescription
--email-estring[]Email address(es) to validate (can be repeated)
--verbose-vboolfalseShow detailed validation information
--jsonboolfalseOutput results as JSON
--fullboolfalsePerform full validation including SMTP check (slower)
--quickboolfalsePerform quick validation (syntax + MX only)

Examples

Basic Validation

bash
$ mailos validate [email protected]

Email Address Validation Results
================================
Checked at: 2025-01-15 10:30:45

  [email protected]

--------------------------------
Summary: 1 valid, 0 invalid

Verbose Output

bash
$ mailos validate [email protected] [email protected] --verbose

Email Address Validation Results
================================
Checked at: 2025-01-15 10:30:45

  [email protected]
   Syntax: OK | Domain: OK | MX: OK
   Mail servers: in1-smtp.messagingengine.com, in2-smtp.messagingengine.com
   Details: Email address appears to be valid and deliverable

  [email protected] - Domain does not exist
   Syntax: OK | Domain: FAIL | MX: FAIL
   Details: The domain 'nonexistent-domain.xyz' could not be found. DNS lookup failed.

--------------------------------
Summary: 1 valid, 1 invalid

JSON Output

bash
$ mailos validate [email protected] --json
json
[
  {
    "email": "[email protected]",
    "is_valid": true,
    "syntax_valid": true,
    "domain_valid": true,
    "mx_valid": true,
    "deliverable": true,
    "details": "Email address appears to be valid and deliverable",
    "mx_records": ["gmail-smtp-in.l.google.com", "alt1.gmail-smtp-in.l.google.com"],
    "checked_at": "2025-01-15T10:30:45Z"
  }
]

Full SMTP Validation

For more thorough validation, use the --full flag which attempts to connect to the mail server:

bash
$ mailos validate [email protected] --full --verbose

Note: SMTP verification can be slow and may be blocked by some mail servers. Many servers reject verification attempts for security reasons, so a failed SMTP check doesn't necessarily mean the address is invalid.

Integration with Send Command

Email validation is automatically enabled when sending emails. The send command will validate all recipients before attempting to send.

bash
# Validation happens automatically (enabled by default)
mailos send --to [email protected] --subject "Hello" --body "Hi there"

# Skip validation if needed
mailos send --to [email protected] --subject "Hello" --body "Hi there" --no-validate

# Force send even if validation fails
mailos send --to [email protected] --subject "Hello" --body "Hi there" --force

# Enable SMTP verification during send
mailos send --to [email protected] --subject "Hello" --body "Hi there" --validate-smtp

Send Command Validation Flags

FlagTypeDefaultDescription
--validatebooltrueValidate recipient email addresses before sending
--no-validateboolfalseSkip email address validation
--validate-smtpboolfalsePerform SMTP verification during validation (slower)

Validation Results

Valid Email

When an email passes all checks:

  • Syntax is correct
  • Domain exists and resolves
  • MX records are configured
  • (Optional) SMTP server accepts the address

Invalid Email - Common Errors

ErrorDescription
Invalid email syntaxEmail format doesn't match RFC 5322 standards
Domain does not existDNS lookup failed - domain may not exist or has expired
No mail server foundDomain has no MX records - cannot receive email
Recipient rejectedSMTP server explicitly rejected the address (full mode only)

Use Cases

Pre-Send Validation

Validate a list of recipients before a bulk send:

bash
# Validate all recipients first
mailos validate [email protected] [email protected] [email protected]

# If all valid, proceed with send
mailos send --to [email protected],[email protected],[email protected] --subject "Newsletter" --file newsletter.md

Scripting and Automation

Use JSON output and exit codes for automation:

bash
# Check exit code (0 = all valid, non-zero = some invalid)
if mailos validate [email protected] --json > /dev/null 2>&1; then
    echo "Email is valid"
else
    echo "Email is invalid"
fi

# Parse JSON output for detailed results
mailos validate [email protected] --json | jq '.[] | select(.deliverable == false)'

Cleaning Email Lists

Validate a list of emails and filter out invalid ones:

bash
# Read emails from file, validate, and output valid ones
cat emails.txt | xargs mailos validate --json | jq -r '.[] | select(.deliverable) | .email'

Performance Notes

  • Quick mode (--quick): Fastest, checks syntax and MX records only (~100ms per email)
  • Default mode: Balanced, includes domain DNS verification (~200-500ms per email)
  • Full mode (--full): Most thorough, includes SMTP verification (~1-5 seconds per email)

For bulk validation, consider using quick mode and only using full validation for critical addresses.

Limitations

  1. SMTP verification is not definitive - Many mail servers block verification attempts or give false positives/negatives
  2. Catch-all domains - Some domains accept all addresses even if the mailbox doesn't exist
  3. Temporary failures - DNS or network issues can cause false negatives
  4. Rate limiting - Validating too many emails quickly may trigger rate limits
  • send - Send emails with automatic validation
  • drafts - Create and manage email drafts
  • search - Search for emails

Released under the MIT License.