Node-mailer或sendGrid在本地运行良好,但是当我在Azure上上载/发布时,其显示为意外令牌{........
var sgMail = require('@sendgrid/mail');
sgMail.setApiKey(Constants.sendGridKey);
var msg = {
to: toWhomSendEmail,
from: Constants.emailID,
subject: "Message from ....",
text: 'and easy to do anywhere, even with Node.js',
html: htmlBody
};
sgMail.send(msg, function (err, result) {
if (err) {
data("false");
} else {
data("true");
}
});
------------ Azure logging errors are just like: ---------------
Mon Apr 08 2019 15:43:02 GMT+0000 (Coordinated Universal Time):
Application has thrown an uncaught exception and is terminated:
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous>
(D:\home\site\wwwroot\node_modules\@sendgrid\mail\src\mail.js:6:21)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
答案 0 :(得分:0)
在这里是在Azure中使用发送网格的先决条件:
1)Node.js版本6、7或8
2)发送网格帐户
能否请您确保是否为节点请求了版本。然后试用这些代码。
super
希望有帮助。