Next.js Discord

Discord Forum

Mailgun error: [Error: Unauthorized] { status: 401, details: 'Forbidden',

Unanswered
Giant panda posted this in #help-forum
Open in Discord
Giant pandaOP
Here's my setup,
I've attached the mailgun client in the screenshot, and here's the trpc procedure,
 sendMail: publicProcedure
      .mutation(async ({ input }) => {
        try {
          const response = await mg.messages.create('sandbox-123.mailgun.org', {  
            from: "Excited User <mailgun@sandbox-123.mailgun.org>",
            to: ["rmadhenkumar@gmail.com"],
            subject: "Hello",
            text: "Testing some Mailgun awesomness!",
            html: "<h1>Testing some Mailgun awesomness!</h1>"
          })
          return { success: true, response };
        } catch (error) {
          console.error("Mailgun error:", error);
          return { success: false, error: "Failed to send email" };
        }
      }),

I am unable to spot the issue,
here's the full error,
Mailgun error: [Error: Unauthorized] {
  status: 401,
  details: 'Forbidden',
  type: 'MailgunAPIError'
}

1 Reply

Giant pandaOP
bump