# Smart Router

Smart Router is a built-in traffic management feature that ensures non-stop email delivery. It allows you to dynamically route traffic and configure automatic failovers directly from the EmailJS Dashboard without modifying a single line of your application code.

You can assign two special routing roles to your email services in the Dashboard:

# 1. Primary

The designated service tied to the abstract primary_service keyword.

Instead of hardcoding a specific service ID in your application, you can use primary_service. EmailJS will automatically route all traffic to the service marked with this role.

The Benefit: If you ever need to change your provider (e.g., switching from Mailgun to Postmark), you just reassign the Primary role to the new service in the Dashboard. Your production code remains untouched.

// Your production code stays permanent
emailjs.send('primary_service', 'template_id', templateParams);

# 2. Detour

A global alternative route that acts as an automatic failover for your entire account.

Unlike Primary, Detour applies to all email requests. If any email service explicitly requested in your code (whether it's primary_service or a specific hardcoded ID like Gmail_API) experiences an outage or throws a delivery error, Smart Router will automatically retry sending the email via your assigned Detour service.

The Benefit: Total peace of mind. Your users will get their emails even if your specific primary email provider goes completely down.

# Quick Setup

  1. Go to your Email Services tab in the EmailJS Dashboard.
  2. Click the action menu next to your preferred service and select Set as Primary.
  3. Choose any alternative service and select Set as Detour to enable account-wide automatic failover.

# Important Considerations

Quota Usage: When a failover happens, the failed attempt and the successful Detour delivery both interact with your account. A successful detour delivery will consume an additional request credit from your monthly EmailJS quota.

Monitoring & History: Smart Router actions are completely transparent. If a failover occurs, your Email History logs will preserve the full story, showing both the original service that dropped the error and the final service that successfully delivered the email via Detour.

Make sure your Detour service is always fully configured and active to prevent any secondary delivery failures.