1

次のコードを使用して、pdf が添付された電子メールを送信しています。

class StudyMailer < ActionMailer::Base
  def notify_office(study, sent_at = Time.now)
    subject    "Email Subject Goes Here"
    recipients 'user@domain.come'
    from       "#{study.sender.full_name} <#{study.sender.email}>"
    sent_on    sent_at
    body       :study => study
    for document in study.documents   
      attachment :content_type => "application/pdf", :body => File.read(document.document.path) #absolute path to .pdf document
    end
  end
end

電子メールが送信されると、添付ファイルは .pdf 添付ファイルとしてではなく、バイナリ コードとしてインラインでレンダリングされるようです。

インラインではなく、一般的な添付ファイルとして .pdf をレンダリングするにはどうすればよいですか?

4

3 に答える 3

1
attachment :content_type => "application/pdf", 
    :content_disposition => "attachment", 
    :filename => File.basename(fattach), 
    :body => File.new(fattach,'rb').read() 

content-disposition 行に注意してください。

于 2009-12-15T05:20:29.437 に答える
0

電子メールのマルチパートの性質を示す必要があると思うので、次の行を行の下に追加しますfrom

content_type    "multipart/alternative"
于 2009-12-15T05:24:31.997 に答える
0

メールにテンプレートはありますか?メールにテンプレートがない場合、他のすべてが正しく設定されていても、添付ファイルはインラインで表示されます。添付メール テンプレートを作成します。

ビュー/通知/attachment.html.erb

<p>   Please see attachment    </p>

次に、Notifier で、このテンプレートを使用するように指定します。

notifier.rb

def my_email_method
    ...
    mail(:template_name => 'attachment', :from => from_address, ...)
end
于 2012-07-24T17:03:06.790 に答える