sendGrid 邮件不适用于导入

编程入门 行业动态 更新时间:2024-10-04 23:27:13

sendGrid 邮件<a href=https://www.elefans.com/category/jswz/34/1770951.html style=不适用于导入"/>

sendGrid 邮件不适用于导入

const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
  to: '[email protected]',
  from: '[email protected]',
  subject: 'Sending with Twilio 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>',
};
sgMail.send(msg);

以上使用需要导入sendgrid。上面的代码有效。

但是因为我使用的是 ES6 语法,我可以使用 require,我必须使用 import 来代替。

import sgMail from '@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
  to: '[email protected]',
  from: '[email protected]',
  subject: 'Sending with Twilio 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>',
};
sgMail.send(msg);

所以,我写了这段代码,但它给出了错误,因为变量未定义(读取 setApiKey)。当我删除那条线时。它给出错误,因为变量未定义(读取发送)。

回答如下:

import 语句末尾有一个右括号。我想你在转换时错过了删除它。请将其删除并重试。

更多推荐

sendGrid 邮件不适用于导入

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

发布评论

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

>www.elefans.com

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