Rails 中的邮件处理与 Active Resource 应用
1. 接收邮件
在 Rails 应用中处理传入邮件时,可使用 Action Mailer。以下是一个示例代码,展示了如何在邮件中包含 HTML 内容和附件:
part :content_type => "text/html",
:body => render_message("sent", :order => order)
order.line_items.each do |li|
image = li.product.image_location
content_type = case File.extname(image)
when ".jpg", ".jpeg";
"image/jpeg"
when ".png";
"image/png"
when ".gif";
"image/gif"
else;
"application/octet-stream"
end
attachment :content_type => content_type,
:body => File.read(File.join("public", image)),
:filename => File.basename(image)
end
该代码使用 part 指令显式渲染邮件,将其类型设置为 text/html ,并将模板渲染结果作为邮件正文。接着遍历订单中的
订阅专栏 解锁全文

29

被折叠的 条评论
为什么被折叠?



