ruby-on-rails - Ruby on Rails 中的电子邮件模板

标签 ruby-on-rails actionmailer

我需要有关电子邮件模板的帮助。我有一个 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>                     

最佳答案

是否有任何特殊原因需要将它们附加到您的服务器上,而不是托管在您的服务器上,然后在电子邮件中引用(例如 <img src="http://your.server/image.png" /> )?

我想这会简化它。

关于ruby-on-rails - Ruby on Rails 中的电子邮件模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1284469/

相关文章:

ruby-on-rails - 如何删除 ActiveRecord 对象?

ruby-on-rails - 使用 POST/sign_in 登录。不支持 GET。 Omniauth-facebook

ruby-on-rails - 无法在 Rails 邮件 View 中生成删除链接

ruby-on-rails - 我如何测试 ActionMailer?

ruby-on-rails - Rails 3/1.9.2 调试...使用 IDE?

ruby-on-rails - 如何在 Rails 迁移中添加一些插入?

ruby-on-rails - rails : Uninitialized Constant inside Controller

ruby-on-rails - ActionMailer 密码安全

ruby-on-rails - Gmail 的操作邮件程序配置

ruby-on-rails - ApplicationMailer 默认来自标题而不是电子邮件地址?