CI/CD Pipeline Integration
Automate email testing in your CI/CD pipeline. Catch spam issues, accessibility problems, and compatibility bugs before they reach production.
Why Automate Email Testing?
Environment Variables
Configure MailLinter behavior using environment variables. Enable authentication to protect the web interface in shared environments.
AUTH_ENABLEDtrue to require authentication for accessing the web interface.AUTH_USERNAMEAUTH_PASSWORDdocker run -p 2525:2525 -p 8547:8547 \ -e AUTH_ENABLED=true \ -e AUTH_USERNAME=admin \ -e AUTH_PASSWORD=secretpass \ nunomsde/maillinter
Pipeline Configuration
name: Email Testing
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
email-test:
runs-on: ubuntu-latest
services:
maillinter:
image: nunomsde/maillinter
ports:
- 2525:2525
- 8547:8547
env:
AUTH_ENABLED: true
AUTH_USERNAME: ${{ secrets.MAILLINTER_USER }}
AUTH_PASSWORD: ${{ secrets.MAILLINTER_PASS }}
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Wait for MailLinter
run: |
timeout 30 bash -c 'until curl -s http://localhost:8547/api/emails; do sleep 1; done'
- name: Run email tests
run: npm run test:email
- name: Check email analysis
run: |
# Get all emails and check spam scores
EMAILS=$(curl -s http://localhost:8547/api/emails)
echo "$EMAILS" | jq -e '.emails[] | select(.id) | .id' | while read ID; do
SCORE=$(curl -s "http://localhost:8547/api/emails/${ID}/analysis" | jq '.spam.score')
if (( $(echo "$SCORE > 5.0" | bc -l) )); then
echo "Email $ID has high spam score: $SCORE"
exit 1
fi
doneRecommended Quality Gates
Configure these thresholds to automatically fail builds when email quality drops below acceptable levels.
Spam Score
Emails with spam scores above 5.0 are likely to be filtered
analysis.spam.scoreCritical Accessibility
Critical WCAG violations that prevent users from accessing content
analysis.accessibility.criticalCompatibility Issues
Number of email clients with rendering problems
analysis.compatibility.issuesAccessibility Warnings
Non-critical accessibility issues that should be addressed
analysis.accessibility.warningsIntegration Steps
Add MailLinter Service
Configure MailLinter as a service container in your pipeline. It exposes SMTP on port 2525 and the API on port 8547.
Configure Application
Set environment variables to point your application's SMTP settings to the MailLinter service.
Run Email Tests
Execute your existing test suite that sends emails. All emails are captured by MailLinter.
Query Analysis API
Use the REST API to retrieve analysis results and validate against your quality thresholds.
Fail or Pass
Based on the analysis results, either pass the build or fail with detailed error messages.
Example Test Script
#!/bin/bash
set -e
API_URL="${MAILLINTER_API:-http://localhost:8547/api}"
MAX_SPAM_SCORE=5.0
MAX_ACCESSIBILITY_CRITICAL=0
echo "Fetching emails from MailLinter..."
EMAILS=$(curl -s "$API_URL/emails")
COUNT=$(echo "$EMAILS" | jq '.total')
if [ "$COUNT" -eq 0 ]; then
echo "No emails found. Make sure your tests sent emails."
exit 1
fi
echo "Found $COUNT email(s). Analyzing..."
echo "$EMAILS" | jq -r '.emails[].id' | while read ID; do
ANALYSIS=$(curl -s "$API_URL/emails/$ID/analysis")
SUBJECT=$(curl -s "$API_URL/emails/$ID" | jq -r '.subject')
SPAM=$(echo "$ANALYSIS" | jq '.spam.score')
CRITICAL=$(echo "$ANALYSIS" | jq '.accessibility.critical')
echo "Email: $SUBJECT (Spam: $SPAM, Critical A11y: $CRITICAL)"
if (( $(echo "$SPAM > $MAX_SPAM_SCORE" | bc -l) )); then
echo "FAIL: Spam score exceeds threshold"
exit 1
fi
if [ "$CRITICAL" -gt "$MAX_ACCESSIBILITY_CRITICAL" ]; then
echo "FAIL: Critical accessibility issues found"
exit 1
fi
done
echo "All emails passed validation!"What's Next?
CI/CD Tips
Performance
- Use service containers instead of docker-compose
- Add health checks to avoid race conditions
- Cache the MailLinter image when possible
Debugging
- Output full analysis on failure for debugging
- Save email artifacts for manual inspection
- Use verbose logging in test scripts