Issues with MailGun

I'm attempting to add MailGun as my email provider, but running into some issues - whenever I attempt to use mailgun, I get a dependency error from ts-mailgun:
Uncaught TypeError: Cannot read properties of undefined (reading '__agent_base_https_request_patched__')
at ../../../node_modules/proxy-agent/node_modules/agent-base/patch-core.js (ts-mailgun.js?v=6165f70e:822:23)
Uncaught TypeError: Cannot read properties of undefined (reading '__agent_base_https_request_patched__')
at ../../../node_modules/proxy-agent/node_modules/agent-base/patch-core.js (ts-mailgun.js?v=6165f70e:822:23)
I investigated this and whilst there's little info online, I did find this on stackoverflow which says that version 0.5 (the version of wasp) has the issue, and 0.18 fixes it - https://stackoverflow.com/questions/50906419/cannot-read-property-validate-of-undefined-in-mailgun-js I am using wasp v0.13.2
Stack Overflow
Cannot read property 'validate' of undefined in mailgun-js
I am using mailgun-js to validate emails. I'm implementing the same way as described in the documentation mailgun-js documentation. my code : var domain = 'postmaster.xxxx.in'; var api_key = 'pub...
18 Replies
kapa.ai
kapa.ai5mo ago
Hi @CamBlackwood. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Hmm, I don't know enough to give you a confident answer yet. The knowledge sources provided do not contain information about the specific error you're encountering with ts-mailgun and Wasp. However, I can guide you on how to set up Mailgun as your email provider in Wasp. You need to set the provider to Mailgun in the main.wasp file and then get the Mailgun API key and domain and add them to your .env.server file. Here is how you can do it: In your main.wasp file:
app Example {
...
emailSender: {
provider: Mailgun,
}
}
app Example {
...
emailSender: {
provider: Mailgun,
}
}
In your .env.server file:
MAILGUN_API_KEY=
MAILGUN_DOMAIN=
MAILGUN_API_KEY=
MAILGUN_DOMAIN=
You can get the API key and domain by creating an account on Mailgun, creating a new API key and domain, and then adding them to your .env.server file. For more detailed instructions, you can refer to the Wasp documentation (https://wasp-lang.dev/docs/advanced/email#using-the-mailgun-provider). For the specific error you're encountering, I would recommend reaching out to the Wasp community on Discord (https://discord.gg/rzdnErX) or via email at [email protected] for more assistance. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @CamBlackwood, 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?
CamBlackwood
CamBlackwood5mo ago
Sorry, I should also add that as far as I can tell my env file is correct. (api key and domain), happy to DM these to a wasp team member though to verify
miho
miho5mo ago
Let me check what is going on 😊
Janus
Janus4mo ago
Hi! I'm facing the same issue as @CamBlackwood Any updates in this regard? Thanks in advance! @kapa.ai
kapa.ai
kapa.ai4mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- I'm sorry, but the knowledge sources provided do not contain any information about an issue reported by a user with the ID 772532264775975003. Therefore, I'm unable to provide any updates or solutions in this regard. For specific issues, I recommend reaching out to the Wasp community on Discord (https://discord.gg/rzdnErX) or via email at [email protected] for more assistance. They might be able to provide more context and potential solutions. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Janus, 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?
miho
miho4mo ago
Sorry for dropping the ball on this, I still haven't tested this out 😢 @CamBlackwood did you manage to resolve this one?
CamBlackwood
CamBlackwood4mo ago
Still broken for me unfortunately
miho
miho4mo ago
So, I've tested it out like this with Wasp 0.13.2:
app mailgunTest {
wasp: {
version: "^0.13.2"
},
title: "mailgun-test",
emailSender: {
provider: Mailgun
},
server: {
setupFn: import { setupServer } from "@src/serverSetup"
}
}

route RootRoute { path: "/", to: MainPage }
page MainPage {
component: import { MainPage } from "@src/MainPage"
}
app mailgunTest {
wasp: {
version: "^0.13.2"
},
title: "mailgun-test",
emailSender: {
provider: Mailgun
},
server: {
setupFn: import { setupServer } from "@src/serverSetup"
}
}

route RootRoute { path: "/", to: MainPage }
page MainPage {
component: import { MainPage } from "@src/MainPage"
}
import { emailSender } from "wasp/server/email";

export async function setupServer() {
console.log("Server setup started.")
const result = await emailSender.send({
from: {
name: "Wasp",
},
subject: "Test email",
text: "Hello, this is a test email.",
html: "<h1>Hello, this is a test email.</h1>",
})
console.log("Email sent, result:", result)
}
import { emailSender } from "wasp/server/email";

export async function setupServer() {
console.log("Server setup started.")
const result = await emailSender.send({
from: {
name: "Wasp",
},
subject: "Test email",
text: "Hello, this is a test email.",
html: "<h1>Hello, this is a test email.</h1>",
})
console.log("Email sent, result:", result)
}
and env vars:
MAILGUN_API_KEY=3c40b68e8ed65d50447ae6e5d95c614d-6fafb9bf-XXXXXXX
MAILGUN_DOMAIN=sandbox6de6c429ca134b5bb6aa28f06449XXXX.mailgun.org
MAILGUN_API_KEY=3c40b68e8ed65d50447ae6e5d95c614d-6fafb9bf-XXXXXXX
MAILGUN_DOMAIN=sandbox6de6c429ca134b5bb6aa28f06449XXXX.mailgun.org
And it worked for me 😄
miho
miho4mo ago
No description
miho
miho4mo ago
@CamBlackwood was this similar to your setup or @Janus your setup?
CamBlackwood
CamBlackwood4mo ago
Will confirm in the next 30 mins 🙂
miho
miho4mo ago
Thank you 👍 let me know how it goes
Janus
Janus4mo ago
Thanks for your support and help @miho 🙂 But I’m still having the same issue. I adapted your setup for my contact form where I want to use emailSender, but I'm still getting the same error that @CamBlackwood mentioned.

const handleSubmit = async (event: React.FormEvent) => {
event.preventDefault();

try {
const result = await emailSender.send({
from: {
name: "App Test",
},
subject: "Test email",
text: "Hello, this is a test email.",
html: "<h1>Hello, this is a test email.</h1>",
});
console.log("Email sent, result:", result);
setFormStatus('Email sent successfully');
} catch (error) {
console.error("Failed to send email:", error);
setFormStatus('Failed to send email');
}
};

const handleSubmit = async (event: React.FormEvent) => {
event.preventDefault();

try {
const result = await emailSender.send({
from: {
name: "App Test",
},
subject: "Test email",
text: "Hello, this is a test email.",
html: "<h1>Hello, this is a test email.</h1>",
});
console.log("Email sent, result:", result);
setFormStatus('Email sent successfully');
} catch (error) {
console.error("Failed to send email:", error);
setFormStatus('Failed to send email');
}
};

TypeError: Cannot read properties of undefined (reading '__agent_base_https_request_patched__')
at ../../../node_modules/proxy-agent/node_modules/agent-base/patch-core.js (ts-mailgun.js?v=83a55432:819:23)
at __require2 (chunk-PLDDJCW6.js?v=83a55432:17:50)
at ../../../node_modules/proxy-agent/node_modules/agent-base/index.js (ts-mailgun.js?v=83a55432:3853:5)
at __require2 (chunk-PLDDJCW6.js?v=83a55432:17:50)
at ../../../node_modules/proxy-agent/index.js (ts-mailgun.js?v=83a55432:36813:17)
at __require2 (chunk-PLDDJCW6.js?v=83a55432:17:50)
at ../../../node_modules/mailgun-js/lib/request.js (ts-mailgun.js?v=83a55432:38920:22)
at __require2 (chunk-PLDDJCW6.js?v=83a55432:17:50)
at ../../../node_modules/mailgun-js/lib/mailgun.js (ts-mailgun.js?v=83a55432:41613:19)
at __require2 (chunk-PLDDJCW6.js?v=83a55432:17:50)

TypeError: Cannot read properties of undefined (reading '__agent_base_https_request_patched__')
at ../../../node_modules/proxy-agent/node_modules/agent-base/patch-core.js (ts-mailgun.js?v=83a55432:819:23)
at __require2 (chunk-PLDDJCW6.js?v=83a55432:17:50)
at ../../../node_modules/proxy-agent/node_modules/agent-base/index.js (ts-mailgun.js?v=83a55432:3853:5)
at __require2 (chunk-PLDDJCW6.js?v=83a55432:17:50)
at ../../../node_modules/proxy-agent/index.js (ts-mailgun.js?v=83a55432:36813:17)
at __require2 (chunk-PLDDJCW6.js?v=83a55432:17:50)
at ../../../node_modules/mailgun-js/lib/request.js (ts-mailgun.js?v=83a55432:38920:22)
at __require2 (chunk-PLDDJCW6.js?v=83a55432:17:50)
at ../../../node_modules/mailgun-js/lib/mailgun.js (ts-mailgun.js?v=83a55432:41613:19)
at __require2 (chunk-PLDDJCW6.js?v=83a55432:17:50)
It's weird because Mailgun integration works perfectly for user registration verification 🤔 Any ideas on what might be wrong? Thanks again! 🙏
CamBlackwood
CamBlackwood4mo ago
can confirm I've got the exact same issue as well. Are you using open saas @Janus ? Wonder if that could be the issue
miho
miho4mo ago
Oh yeah, you are using wasp/server/email imports in the client code? That is not possible 😄 One more for the detecting server imports on the client issue. https://github.com/wasp-lang/wasp/issues/2067 @martinsos You need to create an action which uses the emailSender and then you need to invoke the action from the client 🙂
GitHub
Detect server imports on the client · Issue #2067 · wasp-lang/wasp
Users sometimes import server specific code from wasp/server/* on the client and it's hard to debug. It's not obvious to new users that this is not something they shouldn't do since the...
CamBlackwood
CamBlackwood4mo ago
ah interesting, that makes sense now that you spell it out. I'll give that a crack and let you know how it goes. Thanks!
martinsos
martinsos4mo ago
@miho in situations like this I just pop a comment in that GitHub issue with link to Discord, to accumulate information + emphasize how much of an issue it is. Did it now for you!
Janus
Janus4mo ago
Thank you very much for the explanation! It finally worked perfectly for me 🙂
Want results from more Discord servers?
Add your server