Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails not sending (ical) attachments in emails

I'm trying to send an email with an ical attachment, I'm running rails v.3.2.13 and using the icalendar gem (to generate the ical string) see. (In development mode in case that might be a problem).

The relevant mailer code looks like this:

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

there is also template file with the same name (mailme.html.erb)

The problem is the mail (html) is send without the attachment. As usual any help would be much appreciated. Thank you.

like image 995
wpp Avatar asked Jan 28 '26 08:01

wpp


1 Answers

I've gotten them working with something like below:

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

So it's possible you need to call it on #attachments on the mail object instead of calling it on the current context. I'm not sure if your mime type needs to be application/ics, but that's worked fine for me in my systems.

like image 149
Josh Kovach Avatar answered Jan 31 '26 00:01

Josh Kovach



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!