RubyOnRails 發送 mail 帶附件

   

   content_type "multipart/mixed"        #郵件裏帶內容和附件
    part "multipart/alternative" do |alternative|
      alternative.part "text/html" do |html|
        html.body = render_message("test.text.html", body)
      end
      alternative.part "text/plain" do |plain|
        plain.body = render_message("test.text.plain", body)
      end
    end
    @data = ""

    file_name = "/images/test.png"
    File.open(file_name,"rb").each {|read| @data << read}
    attachment :content_type => "image/png", :filename => File.basename(file_name), :body => @data


 

   如果是pdf類型的

 

attachment :content_type => "image/png", :filename => File.basename(file_name), :body => @data

 

  在頁面裏,如果不引用圖片,直接以附件形式發送;

  如果引用圖片,可是在郵件的內容處顯示圖片。

 

<img src="test.png" alt="test mail with picture"/>


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章