How to Enable CORS for mail in a box?

I am trying to use the add user api but it fails with the following error in the console.

Access to XMLHttpRequest at ‘https://**/admin/mail/users/add’ from origin 'https://.com’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

Please help!

Hmmm … from where are you sending the request? @ifieldsmart

I have mailinabox setup on a different ec2 and the website from where I am sending the request is hosted on a different ec2.
I am unable to figure out where to add access control headers in the ubuntu ec2 in order to allow requests from the website ec2.

Ok, just wanted to insure that you were not initiating the requests from the MiaB server itself as that seemingly is one reason that error occurs.
Unfortunately, this is an area I have no knowledge concerning … the times I have worked with the API have all been from the command line, or have been with @murgero’s account management script, and have just worked.

If you don’t find any answers here, I’d recommend asking on Github. The developers would have more of an idea about this than most end users I would imagine.

1 Like

Thanks for the tip Alento, I will try my luck on Github.

This doesn’t directly fix your issue, however, i would create a script on your web server and post the data to that, then have the script make a backend http request to the mail server. This way you aren’t exposing all the commands to the front end and you also don’t get the Cors errors. I starting working on this yesterday and works great.