Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

404 when using buildSendMail! #498

Open
JeremyMeissner opened this issue Jun 29, 2024 · 0 comments
Open

404 when using buildSendMail! #498

JeremyMeissner opened this issue Jun 29, 2024 · 0 comments

Comments

@JeremyMeissner
Copy link

JeremyMeissner commented Jun 29, 2024

Describe the bug
Something really weird is happening in my next api route.

If I use the following code I get a 404 like the route doesn't even exist, no console log is printed, no error is thrown, it's like if I was not calling the correct endpoint.

import nodemailer from "nodemailer";
import { buildSendMail } from "mailing-core";
import AccountCreated from "@/emails/AccountCreated";
import React from "react";

export async function POST(req: Request) {
    try {
        const transport = nodemailer.createTransport({
            host: 'smtp.sendgrid.net',
            port: 587,
            auth: {
                user: 'apikey',
                pass: process.env.SENDGRID_API_KEY,
            },
        });

        const sendMail = buildSendMail({
            transport,
            defaultFrom: "noreply@mysender.com",
            configPath: "./mailing.config.json",
        });

        sendMail({
            to: "iam@andireceive.com",
            subject: "hello",
            component: React.createElement(AccountCreated, { name: "Hello" }),
        });

        return Response.json({ success: true }, { status: 200 });
    }
    catch (error) {
        return Response.json({ success: false, error: error }, { status: 500 });
    }
}

BUT if I put comment the sendMail part like the following I get a perfect 200 and so console logs are printed, if I put error voluntary it's thrown and printed.

import nodemailer from "nodemailer";
import { buildSendMail } from "mailing-core";
import AccountCreated from "@/emails/AccountCreated";
import React from "react";

export async function POST(req: Request) {
    try {
        const transport = nodemailer.createTransport({
            host: 'smtp.sendgrid.net',
            port: 587,
            auth: {
                user: 'apikey',
                pass: process.env.SENDGRID_API_KEY,
            },
        });

        const sendMail = buildSendMail({
            transport,
            defaultFrom: "noreply@mysender.com",
            configPath: "./mailing.config.json",
        });

        // sendMail({
        //     to: "iam@andireceive.com",
        //     subject: "hello",
        //     component: React.createElement(AccountCreated, { name: "Hello" }),
        // });

        return Response.json({ success: true }, { status: 200 });
    }
    catch (error) {
        return Response.json({ success: false, error: error }, { status: 500 });
    }
}

What in the hell, in the buildSendMail function cause my next api route to 404? Is that a NextJS thing?

Feel free to ask any additional information if needed.

Versions
nextjs 14.2.4
mailing-core 1.1.0
nodemailer 6.9.14
react 18.3.1

@JeremyMeissner JeremyMeissner changed the title 404 when adding sendEmail! 404 when using buildSendMail! Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant