首页 > 解决方案 > 使用 sendgrid nodejs 发送电子邮件

问题描述

我创建了这个nodejs应用程序来使用sendgrid Api发送电子邮件进行营销,实际上它正在工作,但我有一个问题,我必须删除参数消息to: 'exemple@gmail.com',而不是只在密件抄送收件人的电子邮件中显示它,这是代码:

require("dotenv").config();
const sgMail = require('@sendgrid/mail')
const fs = require("fs");

sgMail.setApiKey(process.env.SENDGRID_API_KEY)

const msg = {

  to: 'exemple@gmail.com',
  from: 'exemple1@gmail.com',
  bcc: ['exemple2@gmail.com','exemple3@gmail.com','exemple4@gmail.com'],
  subject: 'Sending Emails Using Sendgrid',
  html: '<p>Sending Emails Using Sendgrid</p><br><img src="cid:logo" alt="image" />',
  attachments: [{
    filename: 'img',
    type: 'image/png',
    content_id: 'logo',
    content: fs.readFileSync('imgs/img.png', { encoding: 'base64' }),
    disposition: 'inline',
  }],
};

sgMail.send(msg).then(() => {
    console.log('Email sent')
  }).catch((error) => {
    console.error(error)
});

标签: javascriptnode.jsapisendgrid-api-v3bcc

解决方案


查看文档,您应该使用sendMultiple方法而不是send方法。


推荐阅读