如何在后端使用节点JS服务器的sendmail从Webix应用程序发送电子邮件

我想通过单击UI中的button发送来自webix应用程序的电子邮件,该button将通过ajax调用向后端的JS服务器发送发布请求。 webix部分如下所示:

{ id:'tb', view: 'toolbar', cols: [ {view:"button", id:"mail_btn", type:"icon", label:"SendEmail", tooltip:"Send an email", width:100, on: {onItemClick:function(){sendEmail()}} }, ] } 

callback函数:

 function sendEmail() { var bodypart = {"message" : "This is a test mail"}; $.ajax({ type: 'POST', url: '/appl/email', data: bodypart, success: function (data) { console.log("success"); }, error: function(err){ console.log(err); } }); } } 

上面的ajax调用发送一个请求到我使用sendmail npm包的节点JS来实现这一点。 代码如下所示:

 var sendmail = require('sendmail')(); app.post('/appl/email', sendmail()); function sendEmail() { sendmail({ from: 'xyz@support.com', to: 'abc@support.com', subject: 'test sendmail', html: 'Mail of test sendmail ', }, function(err, reply) { console.log(err && err.stack); console.dir(reply); }); } 

但是,我收到以下错误:

 Error: Route.post() requires callback functions but got a [object Undefined] 

有没有办法从webix发送电子邮件本身而不发送请求到节点的JS服务器? 或者如何使用sendmail npm包来实现这个我想要的方式?

任何帮助,将不胜感激。

你的问题不是你使用sendmail的方式,而是你使用快递路线的方式。

这里是一个示例代码,我只是鞭打,给了我你在你的代码相同的错误。

 const express = require('express'); const app = express(); app.get('/', doSomething()); function doSomething() { console.log('this is a sample test'); } app.listen(3000, () => console.log('server is running')); 

问题是app.getapp.get也是如此,具有它需要的特定签名。 传入的函数应该有reqres参数。 您还可以select最后添加next参数。

这是我的上面的代码将如何修复。

 const express = require('express'); const app = express(); app.get('/', (req, res) => { doSomething(); res.json('success'); }); function doSomething() { console.log('this is a sample test'); }