401 Unauthorized Error

If you're getting an "Unauthorised" error (401 code) when trying to send emails, there are several possible causes and solutions.

Common Causes

1. Sending from Unverified Domain

Make sure you're sending from the domain that you've set up and verified in Mailtrap. Using any other domain will result in this error.

2. API Token Permissions

If you've configured a custom API token for your domain, make sure it has proper permissions to send emails.

Check your API tokens and verify the token has:

  • Email sending permissions

  • Access to the correct domain

  • Valid expiration date (if applicable)

3. Incorrect Credentials

Make sure you're using the correct SMTP/API credentials provided in the Integration tab of your domain.

Integration tab showing SMTP and API credentials for both Transactional Stream and Bulk Stream in Mailtrap
SMTP and API credentials in Integration tab

How to Fix

1

Verify Your Domain

  1. Ensure your domain shows the Verified badge

  2. If not verified, complete the DNS record setup

2

Check API Token (if using custom tokens)

  1. Verify the token has Send Email permissions

  2. Ensure it's assigned to the correct domain

  3. Check that the token hasn't expired

3

Verify Credentials

Navigate to: Sending Domains > Integration > Integrate (under Transactional or Bulk Stream)

Copy the exact credentials shown there:

  • For SMTP: Username and Password

  • For API: API Token

Replace your current credentials with these values.

4

Test with cURL

Use the cURL code example to test if the error persists:

  1. Go to Sending Domains > Integration > Integrate

  2. Select your stream (Transactional or Bulk)

  3. Go to Code Samples > cURL

  4. Copy and run the cURL command

Code Samples section in Mailtrap showing cURL integration example
Code Samples section with cURL example

If the cURL test succeeds but your application fails, the issue is with your application's configuration.

Still Having Issues?

If you've verified all the above and still getting 401 errors:

  • Double-check that your FROM address domain matches your verified domain

  • Ensure there are no extra spaces or special characters in your credentials

  • Contact support at [email protected] with:

    • Your domain name

    • The exact error message

    • A code sample showing how you're attempting to send

Last updated

Was this helpful?