发送电子邮件至delayed_job包含:
>纯文本
> HTML(将由不了解内联的常规客户显示)
>“内联”,由Outlook和Thunderbird(使用lightning)识别.
>“常规”附件(#2)
到目前为止有什么用/什么不做:
我可以通过delayed_job发送包含所有部分的电子邮件,但是:
>在Apple的Mail 2附件中显示(而不是一个):
(HTML显示正常)
>在Thunderbird(lightning)中我收到邀请,就像我想要的那样.但警报没有显示出来.
>我必须在渲染的iCal上做一些非常恶心的gsubs才能让ATTENDEES显示出来. (见代码片段)
我的想法:
首先要记住的是:in order to send an email with attachments from delayed_job
To fix this,remember to add this line to your mailer: content_type “multipart/mixed”
据我所知,correct MIME-Type hierarchy因此是:
> multipart / mixed
> multipart / alternative
> text / plain
> text / HTML
> text / calendar(with:method = REQUEST)
>申请/ ics
警告!代码传入.
我目前以下列方式构建此电子邮件:
编辑:我更新了邮件的Rails 4.2(附件必须放在邮件之前)
在我的邮件中.rb
def invitation_email(...) subject = "I suck at email..." attachments["invite.ics"] = { mime_type: "application/ics",content: ical_attachment } email = mail(from: me,to: you,subject: subject) add_ical_part_to(email) emailenddef add_ical_part_to(mail) outlook_body = ical_attachment mail.add_part(Mail::Part.new do content_type "text/calendar; method=REQUEST" body outlook_body end)end
这就是我构建attach附件的方式:
def ical_attachment params_participant = { "RolE" => "REQ-PARTICIPANT","RSVP" => "FALSE","PARTSTAT" => "ACCEPTED" } params_invite = { "CUTYPE" => 'INdivIDUAL',"RolE" => "REQ-PARTICIPANT","PARTSTAT" => "NEEDS-ACTION","RSVP" => "TRUE" } cal = Icalendar::Calendar.new event = Icalendar::Event.new event.dtstart @party.from.to_datetime,{ "VALUE" => "DATE" } event.dtend @party.to.to_datetime,{ "VALUE" => "DATE" } event.summary @party.Title event.description @party.description event.klass "PRIVATE" event.organizer "cn=#{@user.name} #{@user.surname}:mailto:#{@user.email}" # THIS DOES NOT WORK event.alarm.trigger = "-PT5M" # 5 Minutes before... @party.participations.each do |participation| str = "cn=#{participation.user.name} #{participation.user.surname}:mailto:#{participation.user.email}" event.add_attendee(str,params_participant) end @party.invitations.each do |invitee| event.add_attendee("mailto:#{invitee.email}",params_invite) end cal.add_event(event) cal.publish # I KNow THIS IS HORRIBLE AND I HATE IT,BUT OTHERWISE THE ATTENDEES DO NOT SHOW UP cal.to_ical.gsub("ORGANIZER:","ORGANIZER;").gsub("ACCEPTED:","ACCEPTED;").gsub("TRUE:","TRUE;").gsub("PUBliSH","REQUEST")end
任何帮助将非常感激!
正在生成的电子邮件:http://pastebin.com/patf05zd
哦,我在:
> Rails 3.2.13
> Icalendar gem I’m using
而不是icalendar宝石,我现在使用ri_cal.虽然我持怀疑态度,因为最后一次对该回购的承诺是3年前,google group是一个非常有用的资源.
这是我如何生成ical附件(内联和正常),这似乎工作正常(虽然它显然需要一些重构:))
def to_ical# this is horribleklass = selfcal = RiCal.Calendar do event = event do organizer "CN=#{klass.user.name} #{klass.user.surname}:mailto:#{klass.user.email}" summary klass.party.Title description klass.ical_description dtstart klass.party.from.utc.to_datetime dtend klass.party.to.utc.to_datetime location "See url in description" security_class klass.security_class # this is horrible h = self klass.party.participations.each do |participation| h.add_attendee klass.prepare_participant(participation) end klass.party.invitations.each do |invitee| h.add_attendee klass.prepare_invitee(invitee.email) end unless klass.party.reminder == 0 alarm do description "Alarm description" trigger klass.convert_trigger # -PT1H action "disPLAY" end end endend# THE HORRORcal.to_s.gsub("ATTENDEE:","ATTENDEE") .gsub("ORGANIZER:","ORGANIZER;") .gsub("CALSCALE:GREGORIAN","CALSCALE:GREGORIAN\nMETHOD:REQUEST\n")
结束
苹果邮件中的2个附件仍然显示,我不认为可以修复.
总结以上是内存溢出为你收集整理的ruby-on-rails – 如何创建多部分电子邮件? [滑轨]全部内容,希望文章能够帮你解决ruby-on-rails – 如何创建多部分电子邮件? [滑轨]所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)