javascript - 使用 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)
});
解决方案
查看文档,您应该使用sendMultiple
方法而不是send
方法。
推荐阅读
- javascript - 当月日为 31 时,javascript 减去一个月返回当前月份的第一天
- python - Python SQLAlchemy 模拟
- c# - 在datagridview c#中的某些选定行之后更改单元格的值
- html - 双击后引导模式打开而不是在Angular 4中首次单击时打开
- algorithm - 平面度测试算法实现
- django - 在 Django 中的 UpdateView 和 CreateView 之间传递数据
- json - 在 Common Lisp 中访问嵌套的 JSON 字段
- google-apis-explorer - 租户在执行 Google Explorer API 时被列入黑名单
- javascript - 为什么 0.1+0.2+0.3 不等于 0.3+0.2+0.1?
- angular - 防止 HttpClient 在 PUT、POST 和 PATCH 上读取 cookie