Sending multi-page letters and attachments

I am trying to send email using gem 'mail' with Ruby 1.9.3. It contains the text / html and the text / regular part, which should be embedded as alternative parts, as well as an attachment.

This is my current code:

require 'mail' mail = Mail.new mail.delivery_method :sendmail mail.sender = " me@example.com " mail.to = " someguy@example.com " mail.subject = "Multipart Test" mail.content_type = "multipart/mixed" html_part = Mail::Part.new do content_type 'text/html; charset=UTF-8' body "<h1>HTML</h1>" end text_part = Mail::Part.new do body "TEXT" end mail.part :content_type => "multipart/alternative" do |p| p.html_part = html_part p.text_part = text_part end mail.add_file :filename => "file.txt", :content => "FILE" mail.deliver! 

This results in mail with working alternate parts, but without an app. I am using thunderbird 10.0.12 for testing.

I already posted this on github, but unfortunately the posts don't make me smarter. https://github.com/mikel/mail/issues/118#issuecomment-12276876 . Maybe someone can understand the last message a little better than me;)

Can anyone make this example work?

Thanks Krissi

+4
source share
2 answers

This seems to be a mistake regarding the type of content of the attachment. See https://github.com/mikel/mail/issues/522

0
source

I managed to install it like this:

 html_part = Mail::Part.new do content_type 'text/html; charset=UTF-8' body html end text_part = Mail::Part.new do body text end mail.part :content_type => "multipart/alternative" do |p| p.html_part = html_part p.text_part = text_part end mail.attachments['some.xml'] = {content: Base64.encode64(theXML), transfer_encoding: :base64} mail.attachments['some.pdf'] = thePDF mail.content_type = mail.content_type.gsub('alternative', 'mixed') mail.charset= 'UTF-8' mail.content_transfer_encoding = 'quoted-printable' 

Not intuitive, but I read the Pony source code, helped, and also compared the working .eml to what this gem is.

+2
source

All Articles