Ruby Ruby Mail - 如何在 body 中直接显示图片?

uttzebulon · 2013年02月20日 · 最后由 uttzebulon 回复于 2013年03月04日 · 3146 次阅读

请教各位大虾们,如何在用 ruby mail 发出的邮件 body 中直接显示图片?

试过:

Mail.deliver do
  to 1@1.com'
  from [email protected]'
  subject 'testing sendmail'
  html_part do
    content_type 'image/jpeg'
    body File.read('c:\\a.jpeg')
end
end

但是邮件 body 中什么都没显示,console log

Non US-ASCII detected and no charset defined.
Defaulting to UTF-8, set your own if this is incorrect.

不知道该用什么样的 content_type?

你这样相当于挂个附件,肯定显示不出来啊。 手写 html ,邮件中用 table 好布局,照片要用外网能访问到的图片地址,不能像你这样读个本地文件上去,content-type 用 "text/html"

content = <<-HTML
  <table>
    <tr height="500">
      <td width="500">
        <img src="http://xxxxxx.jpg" border="0" />
      </td>
    </tr>
  </table>
HTML

看官方文档:http://guides.rubyonrails.org/action_mailer_basics.html 特别是这一节:2.3.3 Making Inline Attachments

Thanks you all~

需要 登录 后方可回复, 如果你还没有账号请 注册新账号