W
Wasp3d ago
Kynetix

emailSender.send erroring 404 page not found

When I call emailSender.send(), I get the MailgunAPIError error 404 page not found. The Mailgun variables (MAILGUN_DOMAIN, MAILGUN_API_KEY) are setup correctly in .env.server. The following code works fine (it sends the email with no issues): import Mailgun from "mailgun.js"; const mailgun = new Mailgun(FormData); const mg = mailgun.client({ username: "api", key: env.MAILGUN_API_KEY || "API_KEY" }); try { const data = await mg.messages.create("zigozi.co", { from: "Zigozi Support <support@zigozi.com>", to: [to], subject: subject, text: text, html: html, }); but when I swirtch to the following, I get the file not found error. await emailSender.send({ to, subject, text, html }); What page is it talking about? HOw do I fix this??
5 Replies
kapa.ai
kapa.ai3d ago
Hi @Kynetix. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information in the knowledge sources, a 404 "page not found" error from the Mailgun API when using Wasp's emailSender.send() typically indicates that the Mailgun API endpoint is not being reached correctly. Since your direct usage of the Mailgun SDK works, but Wasp's abstraction does not, here are some things to check: 1. Check .env.server Variables
Ensure that both MAILGUN_API_KEY and MAILGUN_DOMAIN are set correctly in your .env.server file. The domain should match exactly what Mailgun expects (e.g., mg.yourdomain.com or zigozi.co as in your example) and not include any typos or extra spaces. Wasp reads these variables as described in the docs, and any mismatch can cause API errors Using the Mailgun Provider. 2. Restart the Wasp Server
After changing environment variables, you must restart your Wasp development server to ensure the new values are loaded. 3. Wasp's emailSender.send() API
The Wasp email sender expects the following fields: from, to, subject, text, and html. If you have set a defaultFrom in your main.wasp, you can omit from in the send call. Otherwise, you must provide it API Reference. Example:
await emailSender.send({
from: { name: "Zigozi Support", email: "support@zigozi.com" }, // Only omit if defaultFrom is set
to,
subject,
text,
html
});

await emailSender.send({
from: { name: "Zigozi Support", email: "support@zigozi.com" }, // Only omit if defaultFrom is set
to,
subject,
text,
html
});

4. Provider Configuration in main.wasp
Make sure your main.wasp is configured to use Mailgun:
app Example {
...
emailSender: {
provider: Mailgun,
}
}

app Example {
...
emailSender: {
provider: Mailgun,
}
}

Using the Mailgun Provider 5. Wasp Version or Bug
There is no mention in the knowledge sources of a known bug causing a 404 with Mailgun, but if all configuration is correct and the error persists, it could be a bug or an unsupported Mailgun feature in Wasp. The knowledge sources do mention that provider-specific options are not yet supported and are being tracked as a feature request Github Issue #1553. Summary:
A 404 error from Mailgun via Wasp's emailSender usually means the domain or API key is not set correctly, or the Wasp server hasn't picked up the latest environment variables. Double-check your .env.server, restart the server, and ensure your main.wasp is configured for Mailgun. If the problem persists and your direct Mailgun code works, it may be a Wasp bug or limitation. If you continue to have issues, consider opening a bug report with your configuration details, as the knowledge sources do not provide a more specific solution for this error. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Kynetix, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Kynetix
KynetixOP3d ago
@kapa.ai I've confirmed the .env.server variables again, and even created a new API key, yet the error's the same. In case this helps, here's the main.wasp setting for sendEmail action sendEmail { fn: import { sendEmail } from "@src/newsletter/sendEmail" } and in the .ts file, here's the code snippet import { emailSender } from 'wasp/server/email'; export const sendEmail: SendEmail<{ to: string; subject: string; text: string; html: string; }, void> = async (args, context) => { const { to, subject, text, html } = args; try { await emailSender.send({ to, subject, text, html }); } catch (error) { console.log("sendemail error", {error}); } } Anything else I'm doing wrong?
kapa.ai
kapa.ai3d ago
Let me check the knowledge base for you again. One moment! :books: Sorry @Kynetix, I am experiencing especially high traffic right now, please try again. :technologist:
Kynetix
KynetixOP3d ago
@kapa.ai I was able to fix it by removing MAILGUN_API_URL from .env.server, which I guess caused some confusion. Thanks
kapa.ai
kapa.ai3d ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Thank you for sharing your solution! Based on the knowledge sources, Wasp's documentation for configuring the Mailgun provider only requires the environment variables MAILGUN_API_KEY and MAILGUN_DOMAIN in your .env.server file—there is no mention of a MAILGUN_API_URL variable being needed or supported. Including unsupported or extra environment variables could indeed cause unexpected behavior or confusion in Wasp's email integration Using the Mailgun Provider. Your fix aligns with the documented setup: only set the variables explicitly required by Wasp for Mailgun, and avoid adding others unless the documentation specifies them. If you encounter similar issues in the future, double-checking the required environment variables in the official docs is a good approach. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Kynetix, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?

Did you find this page helpful?