【发布时间】:2016-07-06 11:11:51
【问题描述】:
我正在使用 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 发送这个吗?如果是这样,你能指出我正确的方向吗?
【问题讨论】: