Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails ActionMailer中的图像不工作--生成超长(内容ID字符串),而不是图像_Ruby On Rails_Ruby On Rails 4_Actionmailer - Fatal编程技术网

Ruby on rails ActionMailer中的图像不工作--生成超长(内容ID字符串),而不是图像

Ruby on rails ActionMailer中的图像不工作--生成超长(内容ID字符串),而不是图像,ruby-on-rails,ruby-on-rails-4,actionmailer,Ruby On Rails,Ruby On Rails 4,Actionmailer,由于调用内联附件,我得到了一个疯狂的长字符串 ----==_mimepart_53aa76257659d_23ff6bff4b848679f6 Content-Type: image/png; charset=UTF-8; filename=tippedlogods.png Content-Transfer-Encoding: base64 Content-Disposition: inline; filename=tippedlogods.png Content-ID: <53aa762

由于调用内联附件,我得到了一个疯狂的长字符串

----==_mimepart_53aa76257659d_23ff6bff4b848679f6 Content-Type: image/png; charset=UTF-8; filename=tippedlogods.png Content-Transfer-Encoding: base64 Content-Disposition: inline; filename=tippedlogods.png Content-ID: <53aa762572f79_23ff6bff4b8486782f@c652b828-9c76-4af2-a50c-d1ff3f5c7273.mail> iVBORw0KGgoAAAANSUhEUgAAAwIAAAE2CAYAAAGlzxW8AAAAGXRFWHRTb2Z0 d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2hpVFh0WE1MOmNvbS5hZG9i ZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2Vo aUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6 bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2 LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpS REYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJk Zi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIg eG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8i IHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5 cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5j b20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRp ZDo5QzUwNkJGNTVCMjM2ODExOEMxNEZBRTQ4MzA2MjI1QiIgeG1wTU06RG9j dW1lbnRJRD0ieG1wLmRpZDo5RENENTgxQkY0MjgxMUUzOTcwQkY4NjIxNDc2 
在my production.rb中:

  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.default_url_options = { :host => 'hidden-peak-xxxx.heroku.com', :only_path => false}
  config.action_mailer.asset_host = 'hidden-peak-xxxx.heroku.com'
  ActionMailer::Base.smtp_settings = {
  :address    => "smtp.sendgrid.net",
  :port       => 587,
  :user_name  => ENV['SENDGRID_USERNAME'],
  :password   => ENV['SENDGRID_PASSWORD'],
  :domain     => ENV['SENDGRID_DOMAIN'],
  :authentication  => :plain
  }

附件就是这样在引擎盖下工作的:一个分隔符,用于标记附件之间的分隔,一个包含附件元数据(例如附件类型)的标题,然后是以某种方式编码的实际图像数据。content id属性可用于引用电子邮件HTML部分的附件

为了实现这一点,电子邮件的整体内容类型需要是多部分内容类型之一,但是您似乎要将其强制为text/html,这使得邮件客户端将整个正文解释为一个文档,而不是将其识别为一系列单独的部分

如果您在调用
mail
时删除了content\u type选项,您应该可以(rails应该从模板的文件名推断电子邮件消息部分的类型)

  def confirmation(order)
    @order = order
    attachments.inline['tippedlogods.png'] = File.read("app/assets/images/tippedlogods.png")
    mail(to: @order.email, subject: "Order Confirmation", content_type: "text/html")
  end
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.default_url_options = { :host => 'hidden-peak-xxxx.heroku.com', :only_path => false}
  config.action_mailer.asset_host = 'hidden-peak-xxxx.heroku.com'
  ActionMailer::Base.smtp_settings = {
  :address    => "smtp.sendgrid.net",
  :port       => 587,
  :user_name  => ENV['SENDGRID_USERNAME'],
  :password   => ENV['SENDGRID_PASSWORD'],
  :domain     => ENV['SENDGRID_DOMAIN'],
  :authentication  => :plain
  }