电子邮件附件使用了错误的文件扩展名

发布于 2025-01-11 02:23:57 字数 1451 浏览 0 评论 0原文

我正在编写一些代码,该代码将创建一个 iCalendar,然后发送一封包含所创建事件的 ics 文件的 Outlook 电子邮件,它按预期工作,但有一个问题。

发送电子邮件时,附件的名称错误(ATT00001.bin 而不是 Meeting.ics),并且它不是作为 .ics 发送,而是作为 .bin 发送。文件的内容仍然如其应有的那样。

任何帮助表示赞赏,谢谢!

        use Spatie\IcalendarGenerator\Components\Calendar;
        use Spatie\IcalendarGenerator\Components\Event;
        ...

        $calendar = Calendar::create('Company test meeting')
            ->event(Event::create()
            ->name('Company test meeting')
            ->description('A test meeting about Company')
            ->startsAt(new \DateTime('24-03-2022 10:00'))
            ->endsAt(new \DateTime('24-03-2022 11:30'))
        )->get();
        
        $mailer = new Mailer('default');
        $mailer->setAttachments([
            'Meeting.ics' => [
                'data' => $calendar,
                'contentDisposition' => false
            ]
        ]);
        $mailer->setFrom(['[email protected]' => 'CompanyName'])
            ->setTo('[email protected]')
            ->setSubject('Company meeting')
            ->deliver('Hey there I would like to have a meeting about Company');

I am working on some code that will create an iCalendar and then send an Outlook email with an ics file of the created event, it works as intended but there is one problem.

When the email gets sent, the attachment is given the wrong name (ATT00001.bin instead of Meeting.ics) and it isn't sent as a .ics but as a .bin. The contents of the file are still just as they are supposed to be.

Any help is appreciated, thanks!

        use Spatie\IcalendarGenerator\Components\Calendar;
        use Spatie\IcalendarGenerator\Components\Event;
        ...

        $calendar = Calendar::create('Company test meeting')
            ->event(Event::create()
            ->name('Company test meeting')
            ->description('A test meeting about Company')
            ->startsAt(new \DateTime('24-03-2022 10:00'))
            ->endsAt(new \DateTime('24-03-2022 11:30'))
        )->get();
        
        $mailer = new Mailer('default');
        $mailer->setAttachments([
            'Meeting.ics' => [
                'data' => $calendar,
                'contentDisposition' => false
            ]
        ]);
        $mailer->setFrom(['[email protected]' => 'CompanyName'])
            ->setTo('[email protected]')
            ->setSubject('Company meeting')
            ->deliver('Hey there I would like to have a meeting about Company');

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挖鼻大婶 2025-01-18 02:23:57

所以我想通了。
当我发送电子邮件时,我正在使用 cakephp 4 食谱。
那里说:“在这种形式中,mimetype 和 contentId 是可选的。”我错误地认为我不需要它。

ics 文件的 mimetype 是文本/日历,所以我只是将其添加到我的 setAttachments 中,如下所示:

$mailer = new Mailer('default');
        $mailer->setAttachments([
            'Meeting.ics' => [
                'data' => $ical,
                'mimetype' => 'text/calendar', //I added the mimetype here
                'contentDisposition' => false
            ]
        ]);
        $mailer->setFrom(['[email protected]' => 'Company'])
            ->setTo('[email protected]')
            ->setSubject('Companymeeting')
            ->deliver("Dummy text " . $attendee . " About " . $description . "");

        $this->set('calendar', $ical);

我仍在研究如何获取正确的文件名,但这并不像文件扩展名那么重要。但如果有人知道,我很想知道。

So I figured it out.
When I was making the email, I was using the cakephp 4 cookbook.
There it said that: "The mimetype and contentId are optional in this form." and I made the mistake of just assuming that I didn't need it.

The mimetype for a ics file is text/calendar so I just added this to my setAttachments like this:

$mailer = new Mailer('default');
        $mailer->setAttachments([
            'Meeting.ics' => [
                'data' => $ical,
                'mimetype' => 'text/calendar', //I added the mimetype here
                'contentDisposition' => false
            ]
        ]);
        $mailer->setFrom(['[email protected]' => 'Company'])
            ->setTo('[email protected]')
            ->setSubject('Companymeeting')
            ->deliver("Dummy text " . $attendee . " About " . $description . "");

        $this->set('calendar', $ical);

I'm still working on how to get the right filename but that isn't as important as the file extension. But if anybody knows, I would love to know.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文