Rails不在电子邮件中发送(ical)附件

时间:2014-02-03 16:40:30

标签: ruby-on-rails ruby ruby-on-rails-3 email

我正在尝试发送包含ical附件的电子邮件,我正在运行rails v.3.2.13并使用icalendar gem(生成string字符串)see。 (在可能出现问题的情况下,在开发模式下)。

相关的邮件代码如下所示:

def mailme
  ical = Icalendar::Calendar.new
  ...
  attachments["meetings.ics"] = { mime_type: "text/calendar", content: ical.to_ical }
  mail(from: email, to: recipient, ...)
end

还有同名的模板文件(mailme.html.erb)

问题是邮件(html)是在没有附件的情况下发送的。 像往常一样,任何帮助将不胜感激。 谢谢。

2 个答案:

答案 0 :(得分:2)

我让他们使用下面的东西:

mail.attachments['meeting.ics'] = { mime_type: 'application/ics',
                                    content: ical.to_ical }
mail(from: email, to: recipient, ...)

因此,您可能需要在#attachments对象上的mail上调用它,而不是在当前上下文中调用它。我不确定你的mime类型是否需要作为应用程序/ ics,但在我的系统中这对我来说很好。

答案 1 :(得分:0)

如果其他人偶然发现了这一点。

如果您使用delayed_job,请查看https://github.com/collectiveidea/delayed_job/wiki/Common-problems#wiki-Sending_emails_with_attachments

要解决此问题,请记住将此行添加到邮件程序中:

content_type "multipart/mixed"
相关问题