Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Rails 3 handles mail differently--and while the simple case is easier, adding the correct MIME hierarchy for multipart email with both alternative content types and (inline) attachments is rather complicated (primarily because the hierarchy needed is so complex.)</p> <p>Phil's answer will seem to work--but the attachments won't be visible on the iPhone (and perhaps other devices) since the MIME hierarchy is still incorrect.</p> <p>The correct MIME hierarchy ends up looking like this:</p> <ul> <li><code>multipart/mixed</code> <ul> <li><code>multipart/alternative</code> <ul> <li><code>multipart/related</code> <ul> <li><code>text/html</code></li> <li><code>image/png</code> (e.g. for an inline attachment; pdf would be another good example)</li> </ul></li> <li><code>text/plain</code></li> </ul></li> <li><code>application/zip</code> (e.g for an attachment--not inline)</li> </ul></li> </ul> <p>I've released a gem that helps support the correct hierarchy: <a href="https://github.com/jcoleman/mail_alternatives_with_attachments">https://github.com/jcoleman/mail_alternatives_with_attachments</a></p> <p>Typically when using ActionMailer 3, you would create a message with the following code:</p> <pre><code>class MyEmailerClass &lt; ActionMailer::Base def my_email_method(address) mail :to =&gt; address, :from =&gt; "noreply@myemail.com", :subject =&gt; "My Subject" end end </code></pre> <p>Using this gem to create an email with both alternatives and attachments you would use the following code:</p> <pre><code>class MyEmailerClass &lt; ActionMailer::Base def my_email_method(address, attachment, logo) message = prepare_message to: address, subject: "My Subject", :content_type =&gt; "multipart/mixed" message.alternative_content_types_with_attachment( :text =&gt; render_to_string(:template =&gt; "my_template.text"), :html =&gt; render_to_string("my_template.html") ) do |inline_attachments| inline_attachments.inline['logo.png'] = logo end attachments['attachment.pdf'] = attachment message end end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload