I’m working on a JavaScript project where I need to send emails using the Mailgun API, but I’m confused about how to properly include authentication. I wrote a sample snippet below, yet I’m not sure where my API key should be inserted or how to format the header to make the authentication work. I would appreciate detailed guidance on placing the API key in the request so that the call is correctly authorized and executed. Here is an updated example:
const initiateEmail = () => {
const requestDetails = {
method: 'POST',
url: 'https://api.mailgun.net/v3/yourSandboxDomain/messages',
headers: {
'Authorization': 'Basic ' + btoa('api:YOUR_NEW_API_KEY')
},
data: {
from: 'Mailgun Tester <postmaster@yourSandboxDomain>',
to: 'Receiver <[email protected]>',
subject: 'Test Email',
text: 'This email serves as a test for sending messages through the Mailgun API using JavaScript.'
}
};
executeRequest(requestDetails);
};
initiateEmail();
Any advice on ensuring that the authentication details are correctly applied would be highly helpful.