Mandrill附件:node.js附件中的日历事件文件为空 [英] Mandrill attachment : calendar event file is empty in attachment with node.js

查看:60
本文介绍了Mandrill附件:node.js附件中的日历事件文件为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 node.js 中的以下代码创建ics文件并将其附加到mandrill电子邮件中:

I am trying to create ics file and attach it to mandrill email by using below code in node.js :

收到的电子邮件具有附件,但附件ics文件为空.我在node.js中使用"ical-generator"

Received email has attachment but the attached ics file is empty. I am using "ical-generator" library in node.js

我从各个线程整理了下面的代码,但没有解决.有人可以帮助我吗?

I have put together below code from various threads but not working out. Could anyone pls help me ?

这是我的代码:

const ical = require("ical-generator");
 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: "Name", email: "address@gmail.com" },
      location: "School",
    };

    const cal = ical({
      name: "My test calendar event",
    });
    cal.domain("mytestwebsite.com");

      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: "Name", email: "address@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 message = {
          html: emailBody,
          subject: "test",
          from_email: "from email",
          from_name: "name",
          to: [
            {
              email: "email address",
            },
          ],
          tags: ["test"],
              attachments: [
                {
                  type: "text/calendar",
                  name: "fileName.ics",
                  content: cal.toString("base64"), // converting to base64 also not working
    // new Buffer.alloc(15, cal.toString()), // this also not working 
                },
              ],
            };
        var async = false;
        var ip_pool = "Main Pool";
        var send_at = moment().format("YYYY-MM-DD HH:mm:ss");
        mandrill_client.messages.send(
          { message: message, async: async, ip_pool: ip_pool, send_at: send_at },
          resolve,
          reject
        );
      });

推荐答案

cal 已经是缓冲区了吗?尝试更改内容: cal.toString("base64") Buffer.from(cal).toString("base64")

Is cal already a buffer? Try changing the content: cal.toString("base64") to Buffer.from(cal).toString("base64")

这篇关于Mandrill附件:node.js附件中的日历事件文件为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆