どのように私はactionmailerのを使用してレンダリングインラインからの電子メールの添付ファイルを防ぐください

StackOverflow https://stackoverflow.com/questions/1905305

質問

私は、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ファイルをレンダリングしていますか?

役に立ちましたか?

解決

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

コンテンツ配置ラインに注目してください。

他のヒント

私はあなたの電子メールのマルチパート性質を示すので、fromラインの下に次の行を追加する必要があると考えています

content_type    "multipart/alternative"

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

  

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

<p>   Please see attachment    </p>

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

  

notifier.rb

def my_email_method
    ...
    mail(:template_name => 'attachment', :from => from_address, ...)
end
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top