仅在确认付款后,如何在 NodeMailer 中发送电子邮件?
Posted
技术标签:
【中文标题】仅在确认付款后,如何在 NodeMailer 中发送电子邮件?【英文标题】:How do I send email in NodeMailer only when payment is confirmed? 【发布时间】:2021-12-29 12:32:12 【问题描述】:当我确认付款并验证付款时,NodeMailer 必须将电子邮件发送到从req.body.email
获得的特定电子邮件 ID。但是我收到了这个错误,并且没有发送电子邮件就完成了付款。
Razorpay 用于支付处理。
Error: **No recipients defined**
at SMTPConnection._formatError (D:\Personal Development\Web Development\nodemailer_payment_integration\node_modules\nodemailer\lib\smtp-connection\index.js:784:19)
at SMTPConnection._setEnvelope (D:\Personal Development\Web Development\nodemailer_payment_integration\node_modules\nodemailer\lib\smtp-connection\index.js:1001:34)
at SMTPConnection.send (D:\Personal Development\Web Development\nodemailer_payment_integration\node_modules\nodemailer\lib\smtp-connection\index.js:615:14)
at sendMessage (D:\Personal Development\Web Development\nodemailer_payment_integration\node_modules\nodemailer\lib\smtp-transport\index.js:227:28)
at D:\Personal Development\Web Development\nodemailer_payment_integration\node_modules\nodemailer\lib\smtp-transport\index.js:285:25
at SMTPConnection._actionAUTHComplete (D:\Personal Development\Web Development\nodemailer_payment_integration\node_modules\nodemailer\lib\smtp-connection\index.js:1550:9)
at SMTPConnection.<anonymous> (D:\Personal Development\Web Development\nodemailer_payment_integration\node_modules\nodemailer\lib\smtp-connection\index.js:540:26)
at SMTPConnection._processResponse (D:\Personal Development\Web Development\nodemailer_payment_integration\node_modules\nodemailer\lib\smtp-connection\index.js:947:20)
at SMTPConnection._onData (D:\Personal Development\Web Development\nodemailer_payment_integration\node_modules\nodemailer\lib\smtp-connection\index.js:749:14)
at TLSSocket.SMTPConnection._onSocketData (D:\Personal Development\Web Development\nodemailer_payment_integration\node_modules\nodemailer\lib\smtp-connection\index.js:189:44)
at TLSSocket.emit (node:events:390:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at TLSSocket.Readable.push (node:internal/streams/readable:234:10)
at TLSWrap.onStreamRead (node:internal/stream_base_commons:199:23)
code: 'EENVELOPE',
command: 'API'
Here is my ejs file screenshot
Here is my server side code
接下来我可以尝试什么?
【问题讨论】:
看起来req.body.email
未定义。这与 razorpay 无关。
你能告诉我现在应该做什么,因为我是初学者,你的帮助对我来说会很棒。
找出req.body.email
未定义的原因
请提供足够的代码,以便其他人更好地理解或重现问题。
【参考方案1】:
在您链接的屏幕截图中,我看不到任何电子邮件字段正在传递
这会导致您的电子邮件字段未定义,从而导致 node-mailer 抛出错误。您必须在发布电子邮件时传递带有数据的对象,这是官方网站上的示例 - https://axios-http.com/docs/post_example
【讨论】:
以上是关于仅在确认付款后,如何在 NodeMailer 中发送电子邮件?的主要内容,如果未能解决你的问题,请参考以下文章
使用 nodemailer 在 Node.JS 中发送电子邮件(错误:554 6.6.0 发送消息以进行传递时出错)