node.js - 如何使用 nodemailer nodejs 发送日历邀请?
问题描述
我正在使用 Nodemailer 发送日历邀请。我面临一个问题,即这会向我发送“invite.ics”文件而不是发送日历邀请。电子邮件发送成功,但它发送“invite.ics”文件。谁能帮我找出问题出在哪里以及如何解决这个问题?提前致谢。
const ical = require('ical-generator');
const cal = ical();
const transporter = nodemailer.createTransport({
service: "Gmail",
host: 'smtp.gmail.com',
port: 587,
secure: false,
auth: {
user: 'vsvishnusingh@gmail.com',
pass: 'mypassword',
}
});
return new Promise(function(resolve,reject){
var options = {
start: moment(),
end: moment().add(1, 'hour'),
timestamp: moment(),
summary: 'My Event',
title : 'Annual function',
description : 'Lets enjoy and relax',
id : 'wdcwe76234e127eugb',
organiser : {'name' : 'Vishnu Singh', 'email':'vsvishnusingh@gmail.com'},
location : 'School'
}
cal.createEvent({
start: new Date(options.start),
end: new Date(options.end),
summary: options.summary || options.subject,
description: options.description || "",
location: options.location,
organizer: {
name: options.organiser.name,
email: options.organiser.email
},
method: 'REQUEST'
});
var mailObj = {
from: "vsvishnusingh@gmail.com",
to: "vishnutest@gmail.com",
subject: "Your Subject",
text: "Some text in the body",
alternatives: [{
contentType: 'text/calendar; charset=UTF-8; method=REQUEST',
content: new Buffer(cal.toString())
}]
};
transporter.sendMail(mailObj, function(err, info){
console.log(err,info);
if (err) {
console.log("Error while sending email ...", err)
reject(err)
} else {
console.log("Email send successfully!");
resolve()
}
});
});
解决方案
推荐阅读
- c# - Automapper 映射复杂的嵌套对象
- c# - 在网络服务器 ASP Net Core/Angular 上保存私有图像的最佳实践
- ios - BLE Mesh 与 Google Home 和 Apple Homekit
- stdstring - 为什么 basic_string::size() & '_M_string_length' 在同一个类中,返回**不同的**值,即使 size() 返回 'size_type _M_string_length'?
- nginx - Odoo 12:如何启用与工人聊天
- c# - 如何使用 C# switch 语句的返回值以 true 或 false 退出任务?
- forms - 移动到另一个屏幕时,如何使下拉列表保持最后选择的选项
- python - 具有多个条件的 Python While 循环未退出
- mysql - Liquibase 验证异常:mysql 中不允许使用 forIndexName
- flask - 识别金家模板分隔符