我无法在nodejs应用程序中使用SendGrid发送邮件(故障)



我在nodejs中使用SendGrid API

这是我的服务器.js

var express = require('express');
var app = express();
var bodyParser = require("body-parser");
const sgMail = require('@sendgrid/mail');
require('dotenv').config();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static('public'));
// http://expressjs.com/en/starter/basic-routing.html
app.get("/", (req, res)=> {
sgMail.setApiKey(process.env.SENDGRID_KEY);
const msg = {
to: 'test@gmail.com',
from: 'test@test.com',
subject: 'Welcome',
text: 'text',
html: '  <body style="margin: 0; padding: 0; background: #2874f0"><style> @font-face {font-family: "Google Sans";font-style: normal;font-weight: 400;src: url("https://fonts.gstatic.com/s/googlesans/v6/4UaGrENHsxJlGDuGo1OIlL3Kwp5eKQtGBlc.woff2") format("woff2");unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;} @import url("https://fonts.googleapis.com/css?family=abc")</style><table align="center" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse;"><tr><td style="padding:20px; color: #fff; font-family: Google Sans"> Hello!</td></tr></table></body>',
};
sgMail.send(msg);
});
// listen for requests :)
var listener = app.listen(process.env.PORT, function() {
console.log('Your app is listening on port ' + listener.address().port);
});

在我的.env文件中

SENDGRID_KEY= MYKEY

我收到错误 env:第 1 行:SENDGRID_KEY:找不到命令

当我在.env文件中留下空格时,我经常遇到类似的问题。仅当"它们在引号内">时,变量值中才可能有空格。

最新更新