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

编程入门 行业动态 更新时间:2024-10-04 07:29:59

<a href=https://www.elefans.com/category/jswz/34/1771452.html style=如何使用@sendgrid/mail 从 Angular v15 发送电子邮件?"/>

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

我正在尝试使用@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>`,
});

回答如下:

更多推荐

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

本文发布于:2024-05-30 23:15:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1771030.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   发送电子邮件   sendgrid   mail   Angular

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!