如何使用@sendgrid/mail 从 Angular v15 发送电子邮件?

问题描述 投票:0回答:0

我正在尝试使用@sendgrid 从 Angular v15 发送电子邮件;但是,我在导入依赖项时遇到以下错误:import { MailService } from "@sendgrid/mail";

我不知道@sendgrid 是否支持更高版本的angular

Cannot find module 'https' or its corresponding type declarations.

1 import * as https from 'https';

任何人都可以帮助将不胜感激。

我安装了所需的依赖项,例如:

npm install @sendgrid/mail,
npm i @types/node

我期待能够从 Angular v15 发送电子邮件模板。 我不知道为什么它不能通过或与角度一起工作。我什至试图从 ChatGPT 获得帮助,但没有成功。

另一方面,我测试了使用没有角度的 Node.js 来发送电子邮件,令人惊讶的是它有效并且我能够收到电子邮件。

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>`,
});

html node.js angular typescript sendgrid
© www.soinside.com 2019 - 2024. All rights reserved.