Reputation: 3
This is my code. Showing 404
import formData from 'form-data';
import Mailgun from 'mailgun.js';
import { PRIVATE_MAILGUN_API_KEY, PRIVATE_MAILGUN_DOMAIN } from '$env/static/private';
const mailgun = new Mailgun(formData);
const client = mailgun.client({
username: 'api',
key: PRIVATE_MAILGUN_API_KEY
});
export const actions = {
sendEmail: async (event) => {
const { request } = event;
const formData = await request.formData();
const messageData = {
from: '[email protected]',
to: '[email protected]',
subject: 'Hello from Mailgun',
text: 'This is an example email sent with Mailgun.',
html: '<strong>This is an example email sent with Mailgun.</strong>'
};
try {
const response = await client.messages.create(PRIVATE_MAILGUN_DOMAIN, messageData);
console.log(response);
return { status: 201, message: 'Email sent' };
} catch (error) {
console.error(error);
return { status: 500, message: 'Failed to send email' };
}
}
};
I'm hoping to integrate mailgun into my sveltekit so that email can be send. But showing this error message: [Error: Not Found] { status: 404, details: '404 page not found\n', type: 'MailgunAPIError' } this is the domain: https://api.mailgun.net/v3/xxxxx.mailgun.org.com/messages
Upvotes: 0
Views: 103
Reputation: 121
Just encountered the same thing and figured I'd post the fix if it helps anyone.
My env PRIVATE_MAILGUN_DOMAIN was set like the mailgun docs: https://api.mailgun.net/v3/yourdomain.com/messages
But mailgun.js is expecting just yourdomain.com
Upvotes: 0