2016-09-05 9 views
0

HTML形式のメールに画像を埋め込み、インラインで表示しようとしていますが、何らかの理由で画像がOutlookソフトウェアに表示されますが、Gmail(オンライン)やOffice 365(オンライン)では表示されません。私はだけでなく、SO What is the right way to embed image into email using Rails?Ruby on Rails:埋め込み画像がGmailやOffice 365に表示されないのはなぜですか?

を問うhttp://api.rubyonrails.org/classes/ActionMailer/Base.htmlに言及されていますそして、私のコードは次のようである:

環境/ development.rbとproduction.rb:

config.action_mailer.asset_host = "http://localhost:3000" 

メールビュー:

<%= image_tag('logo.jpg') %> 

これはOutlookに画像を表示します。

私は、さまざまなを試してみました

<img src="http://localhost:3000/assets/logo-9b88158fa35240340cc52aa5d01800b12e6e1de5ddb99e246bd0583c7a5611cd.jpg" alt="Logo" />

enter image description here

GmailやOffice 365の中

でもない:私はこれについて次のimg srcを取得するログに

enter image description here

さまざまな人々からのアプローチです.SOの質問を含みます:

Unable to render inline attachments in ActionMailer Rails attachments inline are not shown correctly in gmail Send HTML emails with inline images with ActionMailer

それらのどれも私の問題を解決するように見えます。

私がしようとしたコードは次のとおりです。

(試行1)

メーラー:

def send_email(email, unsubscribe) 
    @url = 'http://localhost:3000/users/login' 
    @email = email 
    @unsubscribe = unsubscribe 

    attachments.inline['logo.jpg'] = File.read('C:/Sites/MySite/app/assets/images/logo.jpg') 
    mail(from: "#{@email.from_name} <#{@email.account.email}>", to: @email.to, cc: @email.cc, bcc: @email.bcc, subject: @email.subject, message: @email.message) 
    end 

メールビュー:

<%= image_tag attachments['logo.jpg'].url -%> 

ログイン:

<img src="cid:[email protected]" /> 

----==_mimepart_57cd4b6a9af1e_25703efc6dc78787 
Content-Type: image/jpeg; 
filename=logo.jpg 
Content-Transfer-Encoding: base64 
Content-Disposition: inline; 
filename=logo.jpg 
Content-ID: <[email protected]> 

QzovU2l0ZXMvRWFzeU1haWwvYXBwL2Fzc2V0cy9pbWFnZXMvbG9nby5qcGc= 

----==_mimepart_57cd4b6a9af1e_25703efc6dc78787-- 

(試行2)

メーラー:

def send_email(email, unsubscribe) 
    @url = 'http://localhost:3000/users/login' 
    @email = email 
    @unsubscribe = unsubscribe 

    # THE BELOW LINE 
    attachments.inline['logo.jpg'] = File.join(Rails.root, 'app/assets/images/logo.jpg') 
    mail(from: "#{@email.from_name} <#{@email.account.email}>", to: @email.to, cc: @email.cc, bcc: @email.bcc, subject: @email.subject, message: @email.message) 
    end 

メールビュー:

<%= image_tag attachments['logo.jpg'].url -%> 

(試行3)

メーラー:

def send_email(email, unsubscribe) 
    @url = 'http://localhost:3000/users/login' 
    @email = email 
    @unsubscribe = unsubscribe 
    attachments.inline['logo.jpg'] = { 
           :data => File.read('C:/Sites/MySite/app/assets/images/logo.jpg'), 
           :mime_type => "image/jpg", 
           :encoding => "base64" 
    } 
    mail(from: "#{@email.from_name} <#{@email.account.email}>", to: @email.to, cc: @email.cc, bcc: @email.bcc, subject: @email.subject, message: @email.message) 
    end 

メールビュー:

<%= image_tag attachments['logo.jpg'].url -%> 

これは私にUTFエラーを与える

(試行4)

メーラー:

def send_email(email, unsubscribe) 
    @url = 'http://localhost:3000/users/login' 
    @email = email 
    @unsubscribe = unsubscribe 
    attachments.inline["logo.jpg"] = { 
     mime_type: "image/jpg", 
     content: Base64.encode64(File.read(Rails.root.join("app/assets/images/logo.jpg"))) 
    } 
    mail(from: "#{@email.from_name} <#{@email.account.email}>", to: @email.to, cc: @email.cc, bcc: @email.bcc, subject: @email.subject, message: @email.message) 
    end 

ビュー:

<%= image_tag "data:image/jpg;base64,#{attachments['logo.jpg'].url}" %> 

ログイン:

<img src="data:image/jpg;base64,cid:[email protected]" /> 

----==_mimepart_57cd4c32ea670_25704cedd5879035 
Content-Type: image/jpg 
Content-Transfer-Encoding: base64 
Content-Disposition: inline; 
filename=logo.jpg 
Content-ID: <[email protected]> 

aVZCT1J3bz0K 

----==_mimepart_57cd4c32ea670_25704cedd5879035-- 

しかし、これらのどれも動作するようには思えない、上部のコードだけはOutlookで画像が表示されていることを追加しても価値は、他のすべては、Outlook、Gmailの、とOffice365の画像を見てから私を停止。

私はそれを理解できないので、誰かがこの問題を助けてくれますか?

私が表示されるまで、あなたのコンピュータから画像を読み取ることができない絶対のRails 4.2.6

答えて

0

のGmailを使用しています。

logo.jpgをプロダクションサーバーまたはamazon s3やgoogle picasaなどの別のホストにアップロードするか、ライブフォトURLがある場合は「http://abc.def/logo.jpeg」としてください。

希望すると、これが役立ちます。

関連する問題