Node.js 中的 Nodemailer 问题 - 消息正文中显示主题和占位符问题

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

我在通过 slack 在 Node.js 中使用 Nodemailer 时遇到意外问题,本应位于电子邮件主题行中的主题却出现在消息正文中。下面是相关代码片段

app.view('your_view_callback_id', async ({ ack, body, client }) => {
    console.log('View Submission Payload:', JSON.stringify(body, null));
    const subject = body.view.state.values.uik1r.sl_input.value;
    const message = body.view.state.values["35GrF"].ml_input.value;
    await sendEmail(client, subject, message)
    await ack();
    console.log('Acknowledged view submission', body);
});



async function sendEmail(subject, message){

    console.log('Subject:', subject);
    console.log('Message:', message);

   const transporter =  nodemailer.createTransport({
        host: 'smtp.gmail.com',
        port: 465,
        secure: true,
        auth: {
            user: process.env.EMAIL_USER,
            pass: process.env.EMAIL_PASSWORD,
        }
    })

    const info = await transporter.sendMail({
          from: "SlackEmail <[email protected]>",
          to: "[email protected]",
          subject:`This is just a test ${subject}`,
          text: message
    })
    console.log("message sent:" + info.messageId);
    console.log("Message info:", info);
    console.log("message rejected:" + info.rejected)
}

主题将记录在消息参数下 console.log('消息:', 消息);正如您在日志中看到的那样

消息:技术支持 发送的消息:[电子邮件受保护]“技术支持”应该位于主题下,console.log(主题)甚至不会显示在日志中。

我还遇到了主题行中占位符的问题。我尝试添加一些静态内容,占位符文本未正确显示,导致出现意外内容,例如“这只是一个测试[对象对象]。”,但这确实显示在主题行中

在这里您可以看到完整的有效负载

{
  "type": "view_submission",
  "team": {
    "id": "T7W2JV1EV",
    "domain": "fidelitypaymentserv"
  },
  "user": {
    "id": "UUE442C3E",
    "username": "mekstein",
    "name": "mekstein",
    "team_id": "T7W2JV1EV"
  },
  "api_app_id": "A0678L7J0A3",
  "token": "2IOpUFegFduPd4egrd7BU7Il",
  "trigger_id": "6269446301462.268086987505.739b418412dd1862ec8360bbe92ba936",
  "view": {
    "id": "V0683UZ2E1Z",
    "team_id": "T7W2JV1EV",
    "type": "modal",
    "blocks": [
      {
        "type": "input",
        "block_id": "uik1r",
        "label": {
          "type": "plain_text",
          "text": "Subject",
          "emoji": true
        },
        "optional": false,
        "dispatch_action": false,
        "element": {
          "type": "plain_text_input",
          "action_id": "sl_input",
          "placeholder": {
            "type": "plain_text",
            "text": "Placeholder text for single-line input",
            "emoji": true
          },
          "dispatch_action_config": {
            "trigger_actions_on": [
              "on_enter_pressed"
            ]
          }
        }
      },
      {
        "type": "input",
        "block_id": "35GrF",
        "label": {
          "type": "plain_text",
          "text": "Message",
          "emoji": true
        },
        "optional": false,
        "dispatch_action": false,
        "element": {
          "type": "plain_text_input",
          "action_id": "ml_input",
          "placeholder": {
            "type": "plain_text",
            "text": "Placeholder text for multi-line input",
            "emoji": true
          },
          "multiline": true,
          "dispatch_action_config": {
            "trigger_actions_on": [
              "on_enter_pressed"
            ]
          }
        }
      }
    ],
    "private_metadata": "",
    "callback_id": "your_view_callback_id",
    "state": {
      "values": {
        "uik1r": {
          "sl_input": {
            "type": "plain_text_input",
            "value": "Testing"
          }
        },
        "35GrF": {
          "ml_input": {
            "type": "plain_text_input",
            "value": "P200 is working as expected"
          }
        }
      }
    },
    "hash": "1701380188.P487UEAT",
    "title": {
      "type": "plain_text",
      "text": "Modal Title",
      "emoji": true
    },
    "clear_on_close": false,
    "notify_on_close": false,
    "close": null,
    "submit": {
      "type": "plain_text",
      "text": "Submit",
      "emoji": true
    },
    "previous_view_id": null,
    "root_view_id": "V0683UZ2E1Z",
    "app_id": "A0678L7J0A3",
    "external_id": "",
    "app_installed_team_id": "T7W2JV1EV",
    "bot_id": "B067LAB1GVB"
  },
  "response_urls": [],
  "is_enterprise_install": false,
  "enterprise": null
}

我已经为此工作了几个小时,感谢您为解决此问题提供的任何帮助。

node.js slack-api nodemailer
1个回答
0
投票

看起来你用三个参数调用给定的方法:


await sendEmail(client, subject, message)

但只需要两个:


async function sendEmail(subject, message){

  • 删除未使用的参数
  • 向方法中添加另一个参数,例如
    _client
© www.soinside.com 2019 - 2024. All rights reserved.