使用 Angular 和 SendGrid,我正在尝试发送电子邮件。我正确安装了 NPM 包,但在实现代码时遇到问题。我生成了一个 API 密钥并将其存储在目录中
echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
echo "sendgrid.env" >> .gitignore
source ./sendgrid.env
打字稿是:
sgemail(){
const sgMail = require('@sendgrid/mail'); //ERROR: Cannot find name 'require'.
sgMail.setApiKey(process.env.SENDGRID_API_KEY); //ERROR: Cannot find name 'process'.
const msg = {
to: 'test@example.com',
from: 'test@example.com',
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>',
};
console.log(msg);
sgMail.send(msg);
}
我在单击按钮时触发它。
Sendgrid 在他们的网站上没有关于导入包的信息,例如如何import { Vibration } from '@ionic-native/vibration';
使用 Ionic 的振动包。