I am trying to send an email from Angular v15 using @sendgrid; However, I am getting the errors below on importing the dependencies like : import { MailService } from "@sendgrid/mail";
I don't know if @sendgrid supports later versions of angular or not.
Cannot find module 'https' or its corresponding type declarations.
1 import * as https from 'https';
Anyone can help will be appreciated.
I installed the required dependencies like:
npm install @sendgrid/mail,
npm i @types/node
I was expecting to be able to send email template from Angular v15. I don't know why its not working through or with angular. I even tried to get help from ChatGPT but no success.
On the other hand, I tested to use Node.js without angular to send the email and surprisingly it works and I was able to receive the email.
require("dotenv").config();
const sgMail = require("@sendgrid/mail");
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const sendMail = async (msg) => {
try {
await sgMail.send(msg);
console.log("Message sent successfully");
} catch (error) {
console.error(error);
if (error.response) {
console.error(error.response.body);
}
}
};
sendMail({
to: "[email protected]",
from: "[email protected]",
subject: "Hello Test",
html: `<p style="font-weight: 600; background-color: #ff0000">Hello This is test email</p>`,
});