电子邮件附件使用了错误的文件扩展名
我正在编写一些代码,该代码将创建一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以我想通了。
当我发送电子邮件时,我正在使用 cakephp 4 食谱。
那里说:“在这种形式中,mimetype 和 contentId 是可选的。”我错误地认为我不需要它。
ics 文件的 mimetype 是文本/日历,所以我只是将其添加到我的 setAttachments 中,如下所示:
我仍在研究如何获取正确的文件名,但这并不像文件扩展名那么重要。但如果有人知道,我很想知道。
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:
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.