我需要有关电子邮件模板的帮助。我有一个带有三个嵌入图像的html模板。我正在使用restful身份验证插件,并尝试自定义默认邮件程序。该模板非常适合作为独立的网页,但由于某些原因,图像无法正确呈现。我可以让图像附加但不能渲染内联,或者根本不附加。
无论如何,邮件如下:
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>
答案 0 :(得分:3)
是否有任何特殊原因需要连接而不是托管在您的服务器上,然后在电子邮件中引用(例如<img src="http://your.server/image.png" />
)?
我想这会简化它。
答案 1 :(得分:0)
如果您坚持要附加它们,请尝试使用Json King的内联附件gem。最适合静态图像。
链接:http://github.com/JasonKing/inline_attachment/tree/master