On Friday, July 22, 2011 5:27:18 AM UTC-6, Ruby-Forum.com User wrote:
>
> i got a problem with rails achtionmailer 3.0.7.
>
> when i send a email with attachment, sometimes the attachment is not
> displayed as such and is not be found in the email, but the size of the
> email is still big (as with attachment). it's probably hidden base64
> encoded in the sourcecode.
>
> now the hard part. i only got this information from customers and cannot
> stage this error in my development environment.
>
> my code is quite easy:
>
> def offer(docs = [])
>   # attach files
>   docs.compact.each do |document|
>     attachments[document.filename] = File.open(document.url, 'rb')
> {|file| file.read} ## I need to read 'rb' because i am on a win-server
>   end
>
>   mail(:to => "<email>", :subject => "<subject>")
> end
>
> any suggestions? how can i assure, that the attachment will be
> displayed?
> the attachments are always pdfs (if thats somehow important).
>
> -- 
> Posted via http://www.ruby-forum.com/.
>

The attachment is most likely there. It's likely not displayed by the client 
due to the way the actionmailer and/or mail gem structured the email (in 
terms of the "multipart/*" hierarchy). Some clients are pickier than others 
and won't display parts ("attachments") unless the exact, "proper" structure 
is followed.

To be sure this is the problem, however, you need to open the email in a 
text editor and sketch out the structure of its parts. For example, a 
typical email (w/a text and html part) with a file attachment and some 
inline images (displayed by the HTML) might look like:

* Main email: multipart/mixed
  > First part: multipart/alternative
    + First sub-part: text/plain (text version of email)
    + Second sub-part: multipart/related (container for html part)
      - First sub-sub-part: text/html
      - Second sub-sub-part: image/png (displayed in html using cid 
reference)
      - Third sub-sub-part: image/jpeg (ditto)
      - ...
  > Second part: application/pdf (attached PDF file)
  > Third part: image/jpeg (attached image file)
  > ...

The above structure is tried and true and displays in most (all?) email 
clients (yes, I've had this issue before and hand-coded my own wrapper 
around the mail gem to guarantee this structure; we've tested it in Outlook, 
Outlook Express, Thunderbird, Evolution, Gmail, Roundcube, ...etc.).

Now, if you've got a plain-text only email the structure can (and should) be 
much simpler.

Let us know what the structure is and we can tell you if this is your 
problem or not.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/ppdSui2TTQgJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to