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.
If you verified example.com, you can only send from *@example.com addresses. Attempting to send from otherdomain.com will fail with a 401 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.

How to Fix
Verify Your Domain
Go to Sending Domains
Ensure your domain shows the Verified badge
If not verified, complete the DNS record setup
Check API Token (if using custom tokens)
Go to API Tokens
Verify the token has Send Email permissions
Ensure it's assigned to the correct domain
Check that the token hasn't expired
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.
Test with cURL
Use the cURL code example to test if the error persists:
Go to Sending Domains > Integration > Integrate
Select your stream (Transactional or Bulk)
Go to Code Samples > cURL
Copy and run the cURL command

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
Related Articles
Last updated
Was this helpful?

