2013-05-24 2 views
5

아래 코드에서 내가 잘못하고있는 부분을 누군가가 도와 줄 수 있기를 바랬습니다. 대부분의 이메일 클라이언트 (Gmail 웹, 안드로이드),하지만 아이폰/ipad에 제대로 렌더링되지 않습니다 : HTML 콘텐츠 또는 텍스트 콘텐츠가 표시되지 않고 마지막으로 첨부 된 그림 만 표시됩니다. 모든 이메일 클라이언트가 페이로드를 다르게 해석하고 렌더링한다는 것을 이해합니다. 아이폰에서 작동하도록하는 방법을 모르겠습니다.인라인 이미지가있는 html 이메일이 iphone에서 제대로 렌더링되지 않음

도움을 주셨습니다.

루비 코드 :

require 'mail' 

def inline_body_with_attachments(html, attachments) 
    attachments.each do |attachment| 
     if (html =~ /#{attachment.filename}/) 
      html = html.sub(attachment.filename, "cid:#{attachment.cid}") 
     end 
    end 
    return html 
end 


mail = Mail.new({ 
    :from => "[email protected]", 
    :to  => "[email protected]", 
    :subject => "html email with inline images" 
}) 

text_part = Mail::Part.new do 
    body "some text" 
end 

mail.text_part = text_part 

# Load the attachments 
attachment = "image.png" 
mail.attachments[attachment] = File.read(attachment) 

inline_html = inline_body_with_attachments("<b>An inline image</b><img src='image.png'/>", mail.attachments) 

html_part = Mail::Part.new do 
    content_type 'text/html; charset=UTF-8' 
    body   inline_html 
end 

mail.html_part = html_part 
mail.deliver! 

같은 이메일 보이는이 도움이 경우 잘 모르겠어요,하지만 난 꽤 많은 코드를 따라, 그리고 내 아이폰에서 작동

Date: Fri, 24 May 2013 13:58:02 +0000 
From: [email protected] 
To: [email protected] 
Message-ID: <[email protected]> 
Subject: test mail with attachment- raw 
Mime-Version: 1.0 
Content-Type: multipart/alternative; 
boundary="--==_mimepart_519f71eab2260_2a1d9e076471d6"; 
charset=UTF-8 
Content-Transfer-Encoding: 7bit 



----==_mimepart_519f71eab2260_2a1d9e076471d6 
Date: Fri, 24 May 2013 13:58:02 +0000 
Mime-Version: 1.0 
Content-Type: text/plain; 
charset=UTF-8 
Content-Transfer-Encoding: 7bit 
Content-ID: <[email protected]> 

some text 

----==_mimepart_519f71eab2260_2a1d9e076471d6 
Date: Fri, 24 May 2013 13:58:02 +0000 
Mime-Version: 1.0 
Content-Type: text/html; 
charset=UTF-8 
Content-Transfer-Encoding: 7bit 
Content-ID: <[email protected]> 

<b>An inline image</b><img src='cid:[email protected]'/> 

----==_mimepart_519f71eab2260_2a1d9e076471d6 
Date: Fri, 24 May 2013 13:58:02 +0000 
Mime-Version: 1.0 
Content-Type: image/png; 
charset=UTF-8; 
filename=image.png 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment; 
filename=image.png 
Content-ID: <[email protected]> 

iVBORw0KGgoAAAANSUhEUgAAASwAAABaCAYAAAACcWsdAAAXUUlEQVR4nGJk 
[.... more image encoding ...] 
DhwFowAXGE0go2CQAAAAAAD//wMAFOkCtHNhXPkAAAAASUVORK5CYII= 


----==_mimepart_519f71eab2260_2a1d9e076471d6-- 
+0

나는 당신을 도울 수 없지만, 내가 해결하려고 노력했던 내 문제 중 하나에 해결책을 제공해 주신 것에 대해 감사드립니다. +1 – GoldfishGrenade

+0

인라인 이미지도 보내려고하지만'.cid' 메쏘드를 찾을 수 없습니다. 생성 된 메쏘드 나 다른 메쏘드에 있나요? – sylvian

+0

nevermind, 질문에 답변 [여기] (http://stackoverflow.com/questions/24273954/inline-images-with-ruby-mail-gem/24274267#24274267) – sylvian

답변

0

5. Microsoft Exchange 서버로 보내고 있습니다.

require 'mail' 

mail = Mail.deliver do 
    to '[email protected]' 
    from '[email protected]' 
    subject 'Inline Image test' 

    add_file './banner.png' 

    pic = attachments['banner.png'] 

    html_part do 
     content_type 'text/html; charset=UTF-8' 
     body "<img width=597 height=162 id='Banner0' src='cid:#{pic.cid}'>" 
    end 

end 

희망이 도움이됩니다.

+0

다음과 같이 몸에 몇 가지 html을 추가 할 수 있습니까? body "Before iamge "이미지를보고 아이폰에 렌더링이 있는지 확인 하시겠습니까? – user316054

+0

시도해 보았지만 제대로 렌더링 된 것처럼 보입니다. 그러나 이미지를 첨부 파일로 표시합니다. – GoldfishGrenade

2

아이폰을 깨우려면 이미지와 함께 html 콘텐츠를 자신의 멀티 파트/관련 부분으로 포장해야했습니다.

require 'mail' 


def inline_body_with_attachments(html, attachments) 
    attachments.each do |attachment| 
     if (html =~ /#{attachment.filename}/) 
      html = html.sub(attachment.filename, "cid:#{attachment.cid}") 
     end 
    end 
    return html 
end 


mail = Mail.new({ 
    :from => "[email protected]", 
    :to  => "[email protected]", 
    :subject => "test mail with attachment- raw4", 
    :content_type => 'multipart/alternative' 
}) 

text_part = Mail::Part.new do 
    body "some text" 
end 

mail.add_part(text_part) 

other_part = Mail::Part.new do 
    content_type 'multipart/related;' 
end 

# Load the attachments 
attachment = "image.png" 
#mail.attachments[attachment] = File.read(attachment) 
other_part.add_file(attachment) 

inline_html = inline_body_with_attachments("<b>An inline image</b><img src='image.png'/>", other_part.attachments) 
html_part = Mail::Part.new do 
    content_type 'text/html; charset=UTF-8' 
    body   inline_html 
end 
other_part.add_part(html_part) 

mail.add_part(other_part) 

mail.deliver! 
관련 문제