关于Rails邮件

针对网页浏览器和手机,我们的Email的content_type分别为"text/html"和"text/plain"
我们可以这样做ruby script\generate mailer Notifier multipart_alternative
app/models/notifier.rb:


def multipart_alternative(recipient, name, sent_at = Time.now)
subject "Test multipart HTML email"
recipients recipient
from 'Old Dog <olddog@examplel.com>'
sent_on sent_at
content_type "multipart/alternative"

part :content_type => "text/html",
:body => render_message("multipart_alternative", :name => name)

part :content_type => "text/plain",
:body => render_message("multipart_alternative_plain", :name => name)

end



我们的两套模板:
1,app/views/notifier/multipart_alternative_plain.rhtml


Hi <%= @name %>!
This is a plain-text message. Enjoy!



2,app/views/notifier/multipart_alternative.rhtml


<html>
<body>
<h1>Hi <%= @name %></h1>
This is a rich-text message. Enjoy!
</body>
</html>



甚至我们可以简化它们:
app/models/notifier.rb:


def implicit_multipart(recipient, name, sent_at = Time.now)
subject "Something for everyone."
recipients recipient
from 'barnam@chadfowler.com'
sent_on sent_at
body(:name => name)
end



然后我们通过给app/views/notifier目录下不同的模板名来做content_type区分,如:
implicit_multipart.text.plain.rhtml和implicit_multipart.text.html.rhtml
这样我们就可以隐式的发送针对不同客户端的Email了


[url=http://kyoleelqh.iteye.com/blog/158184]使用Gmail Smtp 发送email (rails2.0)[/url]

[url=http://www.iteye.com/topic/36627]使用ActionMailer发送邮件(smtp方式)[/url]


[url=http://www.iteye.com/topic/133344]邮件发送问题[/url]

[url=http://www.iteye.com/topic/150775]使用ActionMailer加本机的postfix邮件服务器发送邮件[/url]

[url=http://sinkzephyr.iteye.com/blog/289914]Ruby on Rails 发送邮件环境设置[/url]


[url=http://hi.baidu.com/cxp49/blog/item/02bfe9e700993029b93820c7.html]在rails使用Gmail的smtp服务器发送邮件[/url]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值