我需要電子郵件模板的幫助。我有一個包含三個嵌入式圖像的html模板。我正在使用寧靜的身份驗證插件,並試圖自定義默認的郵件程序。該模板作爲獨立網頁非常有效,但由於某些原因無法正確顯示圖像。我可以讓圖像附加,但不內聯,或者根本不附加。Ruby on Rails中的電子郵件模板
反正郵件程序如下:
class UserMailer < ActionMailer::Base
def signup_notification(user)
setup_email(user)
@subject << 'Please activate your thredUP account'
@body[:url] = "#{APP_CONFIG[:site_url]}/activate/#{user.activation_code}"
end
def activation(user)
setup_email(user)
@subject << 'Your account has been activated - Welcome to thredUP!'
@url = APP_CONFIG[:site_url]
@user = user
content_type "text/html"
attachment :content_type => "image/gif", :body => File.read("#{Rails.root}/public/images/email/bottom-border.gif")
attachment :content_type => "image/gif", :body => File.read("#{Rails.root}/public/images/email/top-border.gif")
attachment :content_type => "image/png", :body => File.read("#{Rails.root}/public/images/email/footer.png")
attachment :content_type => "image/png", :body => File.read("#{Rails.root}/public/images/email/logo-lid.png")
render :layout => 'standard'
end
protected
def setup_email(user)
@recipients = "#{user.email}"
@from = APP_CONFIG[:admin_email]
@subject = "[#{APP_CONFIG[:site_name]}] "
@sent_on = Time.now
@body[:user] = user
end
end
我還內置模板如下:
<html>
<body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0" bgcolor='#EFEFEF' >
<table width="100%" cellpadding="10" cellspacing="40" border="0" class="backgroundTable" bgcolor='#EFEFEF' >
<tr>
<td valign="top" align="center">
<table width="600" cellpadding="0" cellspacing="0">
<tr>
<td style="padding-bottom:15px;"><img src="cid:logo-lid.png"> </td>
</tr>
</table>
<table width="600" cellpadding="0" cellspacing="0">
<tr>
<td><img src="cid:top-border.gif"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="padding:20px;">
<%= yield %>
</td>
</tr>
<tr>
<td><img src="cid:bottom-border.gif"></td>
</tr>
<tr>
<td style="text-align:center; padding-top:15px;">
<img src="cid:footer.png">
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
ok我會嘗試。我想我回想起我的Windows時代,不得不批准下載服務器端圖像。我認爲這已經改變了? – chrishomer 2009-08-18 14:59:55
我不能爲每個客戶說話,但這是大多數通訊服務似乎處理它的方式,並且它很有效。 – 2009-08-18 15:49:38
許多客戶端默認情況下阻止託管圖像[出於很好的理由],但大多數客戶端允許內聯(附加)圖像。 – sandstrom 2011-01-13 15:21:53