我爲日曆使用ics獲得成功的事件,但我想用.ics
附件發送一些文本,爲此我嘗試此代碼,只是看到並告訴我在哪裏必須更改。 我得到event.ics文件,但想發送郵件文本/ html內容的文件。如何在節點js中將email文件附加到.ics文件中?
var ics = require('ics');
var options = {
eventName: 'Fingerpainting lessons',
filename: 'event1.ics',
dtstart: date,
location: 'Here and there',
email: {
name: 'alex bob',
email: email
}
};
ics.createEvent(options, null, function(err, calendar) {
if (!err)
{
console.log('Event file',calendar);
var filePath = path.join('vabo_email', 'email.html');
fs.readFile(filePath, {encoding: 'utf-8'},
function(err, data) {
if (! err)
{
var helper = require('sendgrid').mail;
from_email = new helper.Email('[email protected]')
to_email = new helper.Email(email)
subject = subject
//Dynamic content
var data = data.replace("$content", bodycontent)
content = new helper.Content('text/html', data)
//content = new helper.Content("text/Calendar",calendar)
mail = new helper.Mail(from_email, subject, to_email,content);
var sg = require('sendgrid')('secretekey');
var requestBody = mail.toJSON();
var request = sg.emptyRequest();
request.method = 'POST';
request.path = '/v3/mail/send';
request.body = requestBody;
data = new helper.Content("text/Calendar",calendar)
request.attachments = [{'filename': 'calendar.ics', 'content': data}]
sg.API(request, function (error, response) {
if (! error)
{
console.log('mail send Successfully to',email);
}
else
{
console.log('Error for send mail',error);
}
});
}
else
{
console.log('Error for calendar',err);
}
});
}
else
{
console.log('Error for creating Event',err);
}
});
你會想要刪除並重新創建一個新的API密鑰(在將其包含在上面的代碼片段中後)。如果我是你,我會盡快做到這一點。 –
我看到你編輯了上面的代碼。請確保您仍然銷燬該密鑰並創建了一個新密鑰,因爲任何人都可以查看編輯歷史記錄以查看更改內容以及獲取該API密鑰。 –
遐我改變了它 – Alex