在 Nextjs 13.4 中使用 NodeMailer 时出现连接错误

问题描述 投票:0回答:0

我正在尝试将示例邮件从我的电子邮件发送给其他人,它说

{"message":"Error","error":{"errno":-4039,"code":"ESOCKET","syscall":"connect","address":"40.99.34.150","port":587,"command":"CONN"}}

根据 13.4 的 API 路由处理程序是


export async function GET(request: NextRequest) {
    const transporter = nodemailer.createTransport({
        service: "gmail",
        auth: {
            user: "<my-email>",
            pass: "<valid-password-of-the-above-email>",
        },
    });
    const data = {
        from: "<my-email>",
        to: "<other-email>",
        text: "What",
        html: "<html><body>hello</body></html>",
        subject: "hello",
    };
    try {
        await transporter.sendMail(data);
        return NextResponse.json({ message: "OK" }, { status: 200 });
    } catch (error) {
        return NextResponse.json({ message: "Error", error }, { status: 500 });
    }
}

更新:

参考了下面的链接,但没有太大帮助!

请随意将我重定向到任何其他支持 typescript 和 nextjs 的包

reactjs email next.js nodemailer nextjs13
© www.soinside.com 2019 - 2024. All rights reserved.