Ruby on Railsの中にEメールテンプレート
-
18-09-2019 - |
質問
私は、電子メールテンプレートを支援する必要があります。私はそれで3枚の埋め込まれた画像とHTMLテンプレートを持っています。私は安らかな認証プラグインを使用していますし、デフォルトのメーラーをカスタマイズしようとしています。テンプレートは、スタンドアロンWebページとしてではなく、画像を適切にレンダリングされていない何らかの理由で素晴らしい作品。私は画像をインラインレンダリング添付しなくて取得するか、またはまったく接続しないでください。
の:とにかくメーラーは、次のとおりです。<強いです>
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>
解決
これらが結合ではなく、サーバー上でホストされ、その後、電子メール(例えば<img src="http://your.server/image.png" />
)で参照する必要があること、特定の理由があるのでしょうか?
私はそれを簡略化するだろうと想像します。
他のヒント
あなたがそれらを取り付けることを主張した場合、ジェイソン王のinline_attachment宝石を使用してみてください。静止画像に適しています。
リンク: http://github.com/JasonKing/inline_attachment/tree/master
所属していません StackOverflow