我正在使用npm sendgrid
node sendgrid github
有了这个,我创建了以下模块:
var path = require('path'),
emailTemplates = require('email-templates'),
async = require("async"),
mailConfig = require('../config/email.json'),
templates = require('../config/emailTemplates.json'),
_ = require('lodash'),
sendgrid = require('sendgrid')(mailConfig.sendGridApiKey),
fs = require("fs");
var mymailer = {};
/**
* Sends an email to either one or multiple users
* @param template_id (The id key of the template. Can be found in emailTemplates.json
* @param to String or Array
* @param from String
* @param subject String
* @param keyReplacer Array of objects for keys to replace in the template
* @param files Array of file objects
*/
mymailer.sendTemplate = function (template_id, to, from, subject, keyReplacer, section, text, files) {
var email = new sendgrid.Email(), templateKey = templates[template_id];
if (templateKey) {
email.setSmtpapiTos(to);
email.subject = subject;
email.from = from;
email.text = text;
email.html = 'Gief HTML NU:D';
email.setFilters({
"templates": {
"settings": {
"enable": 1,
"template_id": templateKey
}
}
});
email.smtpapi.header.sub = prepareSub(keyReplacer, section);
email.smtpapi.header.section = prepareSection(section);
email.files = prepareAttachement(files);
sendgrid.send(email);
} else {
console.log('incorrect key');
}
};
现在,对于我的一些邮件,我希望发送一个可以在您的日历中接受的邀请。但是,我不知道如何做到这一点,我似乎无法找到有关该主题的任何信息。
是否有人尝试使用sendgrid发送此内容?如果是这样,你能指出我正确的方向吗?
答案 0 :(得分:3)
如果您愿意升级到最新版本的Node.js SendGrid Client library,您可能会发现v3 / mail / send端点可以更轻松地发送日历邀请。
以下是添加内容类型“文字/日历”的示例:https://github.com/sendgrid/sendgrid-nodejs/blob/master/examples/helpers/mail/example.js#L57
如果您希望直接使用它,请参阅以下有关新v3 / mail / send端点的一些文档:
https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/index.html https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html