RoR ActionMailer出现问题-无法同时发送纯文本和HTML电子邮件. [英] Issue with RoR ActionMailer --cannot send plaintext and HTML emails simultaneously.

查看:58
本文介绍了RoR ActionMailer出现问题-无法同时发送纯文本和HTML电子邮件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Rails应用程序出现问题-我无法同时发送电子邮件的HTML版本和纯文本版本.注意:电子邮件确实会发送;但是,它的样式设置不正确...下面提供了指向结果的链接.

I'm having an issue with my Rails application--I'm having trouble sending both a HTML and plaintext version of my email. NOTE: the email does send; however, it's not styled correctly... there is a link to the results below.

在任何地方都建议,如果要发送HTML,还应该发送纯文本替代.不幸的是,看来我做错了,因为我的应用程序不允许我发送HTML和纯文本,而HTML看起来却很奇怪.

It's recommended everywhere that if you want to send HTML you should also send a plain text alternative too. Unfortunately, it appears that I'm doing something wrong, as my application does not allow me to send both HTML and plaintext, without the HTML looking very weird.

这是我的邮件发送者模型:

here is my mailer model:

class ProjectMembersMailer < ActionMailer::Base

  def membership_invitation(membership)
    @project = membership.project
    @user    = membership.user

    mail( :subject => %(Invitation to join project #{@project.business_name}),
          :from    => %("App" <no-reply@appname.com>),
          :to      => @user.account.email,
          :content_type => "text/html" ) do |format|
        format.html
        format.text
      end
  end

end

我的project_member_mailer视图有两个文件: membership_invitation.html.haml membership_invitation.text.erb (请注意,第二个文件正在使用.erb,即使为了一致性,我将其转换为.haml扩展名.我遇到相同的错误)

My project_member_mailer views have two files: membership_invitation.html.haml and membership_invitation.text.erb (please note that the second file is using .erb, but even if I convert it to a .haml extension for consistency I get the same error)

这里是当我尝试使用上面的代码发送输出时输出的图片.请注意,我删除了一些文本.

Here is picture of that the output looks like when I attempt to send it using the code above. Please note that I removed some of the text.

基本上,它看起来像是在文件的html版本之上发送文本版本.有没有其他方法可以同时发送纯文本和HTML电子邮件呢?还是我想念一些东西-例如,是否应该同时发送这些电子邮件?任何帮助将不胜感激.非常感谢您的时间和帮助!

Basically it looks like it's sending the text version above the html version of the file. Is there an alternate way to sending both plaintext and HTML emails without this happening? Or am I missing something--like, should these emails not be sent simultaneously? Any help would be greatly appreciated. Thank you so much for your time and help!

推荐答案

我遇到了完全相同的问题,只需一件简单的事情即可解决.将format.text放在format.html上

I had the exact same problem, and it can be fixed with just one simple thing. Place format.text over format.html

def membership_invitation(membership)
@project = membership.project
@user    = membership.user

mail( :subject => %(Invitation to join project #{@project.business_name}),
      :from    => %("App" <no-reply@appname.com>),
      :to      => @user.account.email,
      :content_type => "text/html" ) do |format|
    format.text
    format.html
  end
end

这篇关于RoR ActionMailer出现问题-无法同时发送纯文本和HTML电子邮件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆