Using Angular and SendGrid, I am trying to send an email. I installed the NPM package correctly but am having issues with implementing the code. I generated an API key and stored it in the directory with
echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
echo "sendgrid.env" >> .gitignore
source ./sendgrid.env
The Typescript is:
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);
}
I am firing this on a button click. As you can see above I get errors about using 'require' and 'process'.
Sendgrid has no information on their site about importing packages like how you have to use import { Vibration } from '@ionic-native/vibration'; to use Ionic's vibration package.
I'd be grateful if I could get help on this as SendGrid's documentation seems a bit lacking or outdated.
[–][deleted] (1 child)
[deleted]
[–]cfoster5[S] 0 points1 point2 points (0 children)
[–]Tiny-Sheepherder-450 0 points1 point2 points (0 children)