如何解决从node.js应用程序发送电子邮件时nodemailer中的“发件人地址被拒绝”错误?

How to resolve 'Sender address rejected' error in nodemailer when sending email from node.js application?

提问人:rj.dev 提问时间:5/29/2023 更新时间:5/29/2023 访问量:136

问:

我正在更改从我的网站向我的公司电子邮件发送联系电子邮件的方式,我用作邮件提供商,我以前使用 php 来做到这一点,但它有点限制,所以我决定将 nodejs 与 nodemailer 一起使用,我的问题是,当尝试从网络发送电子邮件时会抛出以下错误:hostinger

Error: Can't send mail - all recipients were rejected: 553 5.7.1 <[email protected]>: Sender address rejected: not owned by user [email protected]
code: 'EENVELOPE',
response: '553 5.7.1 <[email protected]>: Sender address rejected: not owned by user [email protected]',
responseCode: 553,
command: 'RCPT TO',
recipient: '[email protected]'

代码如下:

const { Router } = require("express");
const nodemailer = require("nodemailer");
const router = Router();

router.post("/send-email", async (req, res) => {
  const { name, lastName, email, subject, country, whereMeetUs, message } =
    req.body;

  const corpMail = "[email protected]";
  const password = "pass";

  const transporter = nodemailer.createTransport({
    host: "smtp.hostinger.com",
    port: 465,
    secure: true,
    auth: {
      type: "login",
      user: corpMail,
      pass: password,
    },
  });

  const info = await transporter.sendMail({
    from: email,
    to: corpMail,
    subject,
    html: ` 
    <h1>User information</h1>
    <ul>
        <li>User: ${name} ${lastName}</li>
        <li>Mail: ${email}</li>
        <li>Subject: ${subject}</li>
        <li>Country: ${country}</li>
        <li>Where meet us: ${whereMeetUs}</li>
    </ul>
    <h2>Message</h2>
    <p>${message}</p>
    `,
  });

  console.log("Message sent", info.messageId);
  res.redirect("/contact.html");
});

module.exports = router;

我正在寻找的是,从我的网站发送电子邮件时,从表单中写入的地址收到的消息会反映在公司收件箱中,以便您可以直接回复该地址。

<input id="email" name="email" type="email" placeholder="Email" required>

例如,如果我输入该输入,它会反映在与我联系的收件箱中。[email protected][email protected]

节点 .js 表单 电子邮件 Nodemailer

评论


答: 暂无答案