节点邮件程序或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)
以下是在Azure中使用发送网格的先决条件:
1)Node.js版本6,7或8
2)发送网格帐户
如果你是节点的请求版本,请不要请确认。然后试用这些代码。
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
to: '[email protected]',
from: '[email protected]',
subject: 'Sending with SendGrid is Fun',
text: 'and easy to do anywhere, even with Node.js',
html: '<strong>and easy to do anywhere, even with Node.js</strong>',
};
sgMail.send(msg);
希望能帮助到你。