I added the needed dns configurations on netlify where my website is hosted and when I go to the DNS records of my domain all the ticks on all the fields(TXT, MX, CNAME) are green so I know the domain is verified. However I am unable to use the domain when sending messages and get this error:
Error: Forbidden
at IncomingMessage.<anonymous> (C:\Users\MSI\Desktop\mail\node_modules\mailgun-js\lib\request.js:327:17)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (_stream_readable.js:1220:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
statusCode: 401
}
Here is the code that I copied from the mailgun docs and changed the values to my domain and my api key:
const mailgun = require('mailgun-js');
const DOMAIN = 'example.com';
//The domain is written in the exact same form (not https://example.com)
const api_key = '****************************************';
const mg = mailgun({ apiKey: api_key, domain: DOMAIN });
const data = {
from: 'Name <myemail@gmail.com>',
to: 'myemail@gmail.com',
subject: 'Hello',
text: 'Testing some Mailgun awesomness!',
};
mg.messages().send(data, (err, body) => {
if (err) throw err;
console.log(body);
});
I have looked through all the stackoverflow questions on this topic it seems like but still didnt find what the issue is (And again, the code above is working with a sandbox domain). help