【问题标题】:Access images in public folder from pages/api in nextJS using nodemailer使用 nodemailer 从 nextJS 中的 pages/api 访问公共文件夹中的图像
【发布时间】:2022-07-08 04:19:11
【问题描述】:

使用这些版本

"next": "12.0.7"
"nodemailer": "^6.7.2"

我正在使用 NextJS 构建邮件服务,但遇到了一些问题:

  • gmail 不渲染图像(通过将我要渲染的图像作为附件发送来解决)
  • 在生产中,邮件服务找不到公用文件夹中的图像
  • 在开发环境中发送的邮件完美无缺,但在生产环境中无法渲染图像

我有以下结构

pages
   -api
       -contact.js
public
   -images
       -image_name.png

在contact.js中

如建议here

...

 mailData = {
                from: process.env.THE_EMAIL,
                to: req.body.email,
                subject: `SOME_SUBJECT`,
                attachments: [
                    {
                        filename: 'image_name.png',
                        path: 'public/images/image_name.png',
                        cid: 'SOME_ID_FOR_NODEMAILER',
                    }
             ]}

...

当我在 localhost 中工作时,邮件服务运行良好并且可以找到图像,但是在生产中(使用 Vercel 部署)时却找不到图像。

有什么想法或替代方案吗? 我应该将图像托管在 CDN 中并忘记它吗?

【问题讨论】:

  • 您是否找不到它们,或者您的软件找不到它们?
  • 软件找不到他们,我收到系统找不到文件的错误
  • 你检查过所有者\权限吗?
  • 这是否回答了您的问题:Next.js: How to get static assets from within getStaticProps?尝试使用path.join(process.cwd(), 'public/images/image_name.png') 作为图像的路径。

标签: next.js serverless nodemailer


【解决方案1】:

遇到同样的问题;好奇你是怎么解决这个问题的。

【讨论】:

    猜你喜欢
    • 2022-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-27
    • 2020-10-23
    • 2017-03-23
    • 1970-01-01
    • 2014-12-04
    相关资源
    最近更新 更多