title: Rails mailer error with inline attachment
body: <p>I have a very rare behavior in Action Mailer, I had implement a mailer action like 5 months ago and it was working, but yesterday, for some strange reason, it crashed.</p>
  
  <h3>The problem</h3>
  
  <p>I have a mail layout, in order to use it in all my emails, in it I render an image that is attached previously by a before filter</p>
  
  <p>Layout = <code>app/views/layouts/email.html.erb</code></p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
      &lt;title&gt;Visionamos&lt;/title&gt;
      &lt;link rel="stylesheet" type="text/css" href=&lt;%="/assets/email.css" %&gt;&gt;
    &lt;/head&gt;
    &lt;body&gt;
     &lt;table&gt;
      &lt;tr&gt;
       &lt;td id="head"&gt;
        &lt;table&gt;
         &lt;tr class="image"&gt;
           &lt;td&gt;&lt;%= image_tag(attachments['visionamos.png'].url) %&gt;&lt;/td&gt;
  ...
  ..
  .
  </code></pre>
  
  <p>User Mailer = <code>app/mailers/users.rb</code></p>
  
  <pre><code>class UsuariosMailer &lt; ActionMailer::Base
    include AbstractController::Callbacks # include controller callbacks
    default :from =&gt; "monitoreo@visionamos.com"
    layout "mail" #Set email layout 
    before_filter :add_inline_attachments! # Add image header for all actions
  
    def otp_password(user, otp_key)
      @usuario = user
      @code = otp_key
      email_with_name = "#{@usuario.nombre} &lt;#{@usuario.email}&gt;"
      mail(:to =&gt; email_with_name, :subject =&gt; "One time password, Plataforma Visionamos")
    end
  
    private
     def add_inline_attachments!
     attachments.inline['visionamos.png'] = File.read("#{Rails.root}/app/assets/images/visionamos.png")
    end
  end
  </code></pre>
  
  <p>Now, when I try to send the email I'm, getting this error</p>
  
  <pre><code>NoMethodError - undefined method `match' for nil:NilClass:
  mail (2.5.4) lib/mail/utilities.rb:112:in `unbracket'
  mail (2.5.4) lib/mail/part.rb:29:in `cid'
  mail (2.5.4) lib/mail/part.rb:33:in `url'
  app/views/layouts/mail.html.erb:13:in     `_app_views_layouts_mail_html_erb__573848672563180413_70191451095440'
  &lt;td&gt;&lt;%= image_tag(attachments['visionamos.png'].url) %&gt;&lt;/td&gt;
  </code></pre>
  
  <p>But the image is attached to the email</p>
  
  <pre><code>&gt;&gt; attachments['visionamos.png']
  =&gt; #&lt;Mail::Part:70191451538040, Multipart: false, Headers: &lt;Content-Type: image/png;   filename="visionamos.png"&gt;, &lt;Content-Transfer-Encoding: binary&gt;, &lt;Content-Disposition: inline; filename="visionamos.png"&gt;, &lt;content-id: &gt;&gt;
  </code></pre>
  
  <h3>My DevEnv</h3>
  
  <p>Mac with Maverics
  Ruby 2.0 + Rails 3.2.16</p>
  
  <h3>Plus</h3>
  
  <ul>
  <li>The email is working in my amazon ec2 instance, in my coworkers environments (ubuntu and mac)</li>
  <li>If I delete the image_tag method in layout, the email is sent and the image is show as attachment, no inline</li>
  </ul>
  
  <h3>Update!!!</h3>
  
  <p>I've tried @Gene solution but even the email is sent, the images are normal attachments, no inline, so looking deeply, I found this</p>
  
  <pre><code>&gt;&gt; attachments.inline['visionamos.png'].header
  =&gt; #&lt;Mail::Header:0x00000106cf6870 @errors=[], @charset=nil, @raw_source="", @fields=[#&lt;Mail::Field:0x00000106cf60c8 @field=#&lt;Mail::ContentTypeField:0x00000106cf5fd8 @charset=nil, @main_type="image", @sub_type="png", @parameters={"filename"=&gt;"visionamos.png"}, @name="Content-Type", @length=nil, @tree=nil, @element=#&lt;Mail::ContentTypeElement:0x00000106cf5d30 @main_type="image", @sub_type="png", @parameters=[{"filename"=&gt;"visionamos.png"}]&gt;, @value="image/png; filename=\"visionamos.png\"", @filename="visionamos.png"&gt;, @field_order_id=23&gt;, #&lt;Mail::Field:0x00000106d17390 @field=#&lt;Mail::ContentTransferEncodingField:0x00000106d172a0 @charset=nil, @name="Content-Transfer-Encoding", @length=nil, @tree=nil, @element=#&lt;Mail::ContentTransferEncodingElement:0x00000106d16ff8 @encoding="binary"&gt;, @value="binary"&gt;, @field_order_id=24&gt;, #&lt;Mail::Field:0x00000106d14a78 @field=#&lt;Mail::ContentDispositionField:0x00000106d14960 @charset=nil, @name="Content-Disposition", @length=nil, @tree=nil, @element=#&lt;Mail::ContentDispositionElement:0x00000106d145c8 @disposition_type="inline", @parameters=[{"filename"=&gt;"visionamos.png"}]&gt;, @value="inline; filename=\"visionamos.png\"", @parameters={"filename"=&gt;"visionamos.png"}, @filename="visionamos.png"&gt;, @field_order_id=26&gt;, #&lt;Mail::Field:0x00000106d3e8f0 @field=#&lt;Mail::UnstructuredField:0x00000106d5ef60 @errors=[["content-id", nil, #&lt;Mail::Field::ParseError: Mail::MessageIdsElement can not parse |&lt;52fe636fae8a6_686085098c087130@MacBook Pro de Ruben.mail&gt;|
  </code></pre>
  
  <p>Reason was: Expected one of !, #, $, %, &amp;, ', *, +, -, /, =, ?, ^, _, `, {, |, }, ~, @, ., ", > at line 1, column 40 (byte 40) after &lt;52fe636fae8a6_686085098c087130@MacBook>]], @charset=#, @name="content-id", @length=nil, @tree=nil, @element=nil, @value="">, @field_order_id=100>]></p>
  
  <p>The interesting part is </p>
  
  <pre><code> #&lt;Mail::Field::ParseError: Mail::MessageIdsElement can not parse |&lt;52fe636fae8a6_686085098c087130@MacBook Pro de Ruben.mail&gt;|
  
   Reason was: Expected one of !, #, $, %, &amp;, ', *, +, -, /, =, ?, ^, _, `, {, |, }, ~, @, ., ", &gt; at line 1, column 40 (byte 40) after &lt;52fe636fae8a6_686085098c087130@MacBook&gt;]],
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/8vqvg.png" alt="Error">    </p>