내 레일 애플리케이션 중 하나에서 PDF 첨부 파일을 보내려고하지만 첨부 파일이 적절한 pdf 대신 텍스트로 제공됩니다. 첨부 파일없이 ASCII 문자레일스 ActionMailer 첨부 파일이 깨진 텍스트로 표시됩니다.
의 매우 긴 문자열로 이어
--
Date: Thu, 23 Feb 2012 13:50:58 -0800
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-ID: <[mailserver]>
Message Body
--
Date: Thu, 23 Feb 2012 13:50:58 -0800
Mime-Version: 1.0
Content-Type: application/pdf;
charset=UTF-8;
filename=invoice.pdf
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename=invoice.pdf
Content-ID: <[mailserver]>
:
내 우편물은 다음과 같습니다 : 내 메일받은 편지함에서 무엇을 얻을
class Notifications < ActionMailer::Base
def contact(email_params, sent_at = Time.now)
subject "" << email_params[:subject]
recipients "" << email_params[:client]
from "#{email_params[:name]} <#{email_params[:address]}>"
attachments['invoice.pdf'] = File.read("#{Rails.root.to_s}/public#{email_params[:attach]}") unless email_params[:attach].blank?
sent_on sent_at
body :message => email_params[:body], :sender_name => email_params[:name]
end
end
그리고 그 헤더 정보는 전송되지 않으며,받은 편지함에 "Message Body"부분 만 있습니다. 나는 내 mailer.rb의 첨부 파일 라인의 File.read() 부분이 어떻게 든 범인이라고 의심하지만 브라우저를 통해 액세스 할 수있는 내 서버의 유효한 pdf 파일을 가리키고 있습니다. 로그는 메일이 올바른 매개 변수와 함께 전송되었다고 말하고 있지만 일반 텍스트 편집기에서 pdf를 여는 경우 디 컴파일 된 텍스트 또는 이와 비슷한 것으로 전송됩니다.
메일 프로그램보기 contact.html.erb는 간단히 : <%= @message %>
입니다. 도움이된다면.
내가 뭘 잘못하고 있을지 모르겠다.
감사합니다.
는 업데이트 :
분명히, 나는 나의 견해 디렉토리에 모두 contact.erb뿐만 아니라 contact.html.erb이 필요했습니다. 그냥 파일을 복사하고 이름을 바꾸면됩니다. 그러나 이제 메시지 본문은 비어 있습니다. 첨부 파일 만 표시됩니다.
이 정보는 도움이됩니다. http://stackoverflow.com/questions/4610689/email-attachments#comment42373470_4610864 –