Hi, I''m trying to add a TMail adapter to the Mack Framework, but
I''m
having problems with attachments. There''s not a whole lot of
documentation on the subject, so I thought I would turn to the gurus.
I want to be able to add a plain text version, an html version, and an
attachment in the email. When I do this I see all 3 displayed in a row
in my email client.
Here''s my simple test script:
### ---
require ''rubygems''
require ''net/smtp''
require ''tmail''
require ''base64''
def deliver(mail)
Net::SMTP.start("localhost", 25) do |smtp|
smtp.sendmail(mail.encoded, mail.reply_to, mail.destinations)
end
end
# setup general mail settings:
mail = TMail::Mail.new
mail.mime_version = "1.0"
mail.to = "mark at mackframework.com"
mail.from = "mark at mackframework.com"
mail.reply_to = mail.from
mail.subject = "hello world"
# Add the text/plain portion
text = TMail::Mail.new
text.mime_version = "1.0"
text.content_type = "text/plain"
text.body = "this is my plain text email"
mail.parts << text
# Add the text/html portion
html = TMail::Mail.new
text.mime_version = "1.0"
html.content_type = "text/html"
html.body = "this is my <b>HTML</b> email"
mail.parts << html
# Add an attachment
content = File.read("/Users/markbates/mark-simpson.png")
attachment = TMail::Mail.new
attachment.body = Base64.encode64(content)
attachment.transfer_encoding = "Base64"
attachment.content_type = "application/octet-stream"
attachment[''Content-Disposition''] = "attachment;
filename=foo.png"
mail.parts << attachment
mail.content_type = "multipart/mixed"
deliver(mail)
### ---
Any help would be great! Thanks.
-------------------------------------------------------------------------------------------------
Mark Bates
mark at mackframework.com
http://www.mackframework.com
http://api.mackframework.com/
http://github.com/markbates/mack
On Thu, Jul 24, 2008 at 11:07 AM, Mark Bates <mark at mackframework.com> wrote:> Hi, I''m trying to add a TMail adapter to the Mack Framework, but I''m having > problems with attachments. There''s not a whole lot of documentation on the > subject, so I thought I would turn to the gurus.What problem are you having? Mikel -- http://lindsaar.net/ Rails, RSpec and Life blog....
Thanks for the quick response Mikel. There was a lot more to my
original email, that outlines the problems I''m having. I''ve
pasted it
below. Thanks for the help.
I want to be able to add a plain text version, an html version, and an
attachment in the email. When I do this I see all 3 displayed in a row
in my email client.
Here''s my simple test script:
### ---
require ''rubygems''
require ''net/smtp''
require ''tmail''
require ''base64''
def deliver(mail)
Net::SMTP.start("localhost", 25) do |smtp|
smtp.sendmail(mail.encoded, mail.reply_to, mail.destinations)
end
end
# setup general mail settings:
mail = TMail::Mail.new
mail.mime_version = "1.0"
mail.to = "mark at mackframework.com"
mail.from = "mark at mackframework.com"
mail.reply_to = mail.from
mail.subject = "hello world"
# Add the text/plain portion
text = TMail::Mail.new
text.mime_version = "1.0"
text.content_type = "text/plain"
text.body = "this is my plain text email"
mail.parts << text
# Add the text/html portion
html = TMail::Mail.new
text.mime_version = "1.0"
html.content_type = "text/html"
html.body = "this is my <b>HTML</b> email"
mail.parts << html
# Add an attachment
content = File.read("/Users/markbates/mark-simpson.png")
attachment = TMail::Mail.new
attachment.body = Base64.encode64(content)
attachment.transfer_encoding = "Base64"
attachment.content_type = "application/octet-stream"
attachment[''Content-Disposition''] = "attachment;
filename=foo.png"
mail.parts << attachment
mail.content_type = "multipart/mixed"
deliver(mail)
### ---
-------------------------------------------------------------------------------------------------
Mark Bates
mark at mackframework.com
http://www.mackframework.com
http://api.mackframework.com/
http://github.com/markbates/mack
On Jul 23, 2008, at 9:55 PM, Mikel Lindsaar wrote:
> On Thu, Jul 24, 2008 at 11:07 AM, Mark Bates
> <mark at mackframework.com> wrote:
>> Hi, I''m trying to add a TMail adapter to the Mack Framework,
but
>> I''m having
>> problems with attachments. There''s not a whole lot of
documentation
>> on the
>> subject, so I thought I would turn to the gurus.
>
> What problem are you having?
>
> Mikel
>
> --
> http://lindsaar.net/
> Rails, RSpec and Life blog....
> _______________________________________________
> Tmail-talk mailing list
> Tmail-talk at rubyforge.org
> http://rubyforge.org/mailman/listinfo/tmail-talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/tmail-talk/attachments/20080723/a499ac4c/attachment.html>
On Thu, Jul 24, 2008 at 12:15 PM, Mark Bates <mark at mackframework.com> wrote:> Thanks for the quick response Mikel. There was a lot more to my original > email, that outlines the problems I''m having. I''ve pasted it below. Thanks > for the help.Dear Mark, No, I have now read your test script twice, and I still don''t have the answer to my question to help you answer your question. You say something vague about being able to see all the parts of the email in the email client. Isn''t this what you are after? What is your expected behaviour? Does it happen when you send HTML only? Does it only happen when you add an attachment? Mikel -- http://lindsaar.net/ Rails, RSpec and Life blog....
Hi Mikel, let me try an clarify. Let''s take a simple case, to start with, when you send an email that has a text/plain and a text/html part, email clients should read that and show you the part that is relevant to you. Meaning that if you say I only want to view my emails in plain text, you''ll see the text/plain part and not the text/html part. I believe I have that working with TMail using the content type multipart/alternative. Now, when I add an attachment to the email, I want that attachment to show up in my email client as just that, an attachment. What is happening, however, is the attachment, as well as the text/ plain, and the text/html parts are all showing up in my email client as one big ''body''. My email client does show the attachment as an attachment, which is great. But the problem I have is that I''m now seeing all three parts showing in the ''body'' of my email, like this: This is my plain text email.This is my HTML email.<image_that_i''ve_attached_here>. Does that help clarify what the problem is? What I want to see is the text/plain version, with an attachment, if I tell my email client that''s what I want, or the text/html version with an attachment, if that''s what I specify. If you still don''t quite understand this, and I know I''m not making the problem terribly clear, let me just ask you, how would you create a multipart email with an attachment using TMail? This, incidentally, would make a great section on the Getting Start pages, as it''s something a lot of people do. I''ve included my headers below, in case that helps you. Thanks. Received: from biglaptop.local ([96.252.48.194]) by mail.helium.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 23 Jul 2008 23:48:21 -0400 Received: from localhost.localdomain (localhost [127.0.0.1]) by biglaptop.local (Postfix) with ESMTP id EAC381E2952E for <mbates at helium.com>; Wed, 23 Jul 2008 23:48:20 -0400 (EDT) From: mark at mackframework.com Reply-To: mark at mackframework.com To: mbates at helium.com Subject: hello world Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=mimepart_4887fb84e1724_42641a37e1f Message-Id: <20080724034820.EAC381E2952E at biglaptop.local> Date: Wed, 23 Jul 2008 23:48:20 -0400 (EDT) Return-Path: mark at mackframework.com X-OriginalArrivalTime: 24 Jul 2008 03:48:21.0397 (UTC) FILETIME=[1DD0C450:01C8ED40] X-TM-AS-Product-Ver: SMEX-7.5.0.1243-5.5.1027-16050.003 X-TM-AS-Result: No--3.942000-8.000000-31 X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No --mimepart_4887fb84e1724_42641a37e1f Mime-Version: 1.0 Content-Type: text/plain this is my plain text email --mimepart_4887fb84e1724_42641a37e1f Content-Type: text/html this is my <b>HTML</b> email --mimepart_4887fb84e1724_42641a37e1f Content-Type: application/octet-stream Content-Transfer-Encoding: Base64 Content-Disposition: attachment; filename=foo.png ------------------------------------------------------------------------------------------------- Mark Bates mark at mackframework.com http://www.mackframework.com http://api.mackframework.com/ http://github.com/markbates/mack On Jul 23, 2008, at 11:17 PM, Mikel Lindsaar wrote:> On Thu, Jul 24, 2008 at 12:15 PM, Mark Bates > <mark at mackframework.com> wrote: >> Thanks for the quick response Mikel. There was a lot more to my >> original >> email, that outlines the problems I''m having. I''ve pasted it below. >> Thanks >> for the help. > > Dear Mark, > > No, I have now read your test script twice, and I still don''t have the > answer to my question to help you answer your question. > > You say something vague about being able to see all the parts of the > email in the email client. Isn''t this what you are after? What is > your expected behaviour? Does it happen when you send HTML only? > Does it only happen when you add an attachment? > > Mikel > > -- > http://lindsaar.net/ > Rails, RSpec and Life blog.... > _______________________________________________ > Tmail-talk mailing list > Tmail-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/tmail-talk
On Thu, Jul 24, 2008 at 1:53 PM, Mark Bates <mark at mackframework.com> wrote:> This is my plain text email.This is my HTML > email.<image_that_i''ve_attached_here>.Oh, I see what you mean now.> If you still don''t quite understand this, and I know I''m not making the > problem terribly clear, let me just ask you, how would you create a > multipart email with an attachment using TMail? This, incidentally, would > make a great section on the Getting Start pages, as it''s something a lot of > people do.Good idea. What email client are you using? Mikel -- http://lindsaar.net/ Rails, RSpec and Life blog....
Dear Mark,
Try setting:
mail.set_content_type ''multipart'', ''mixed'',
{''boundary'' => TMail.new_boundary}
At the top in the first ''mail'' block. You have to set the
multipart
and mixed separately. You can set the boundary to whatever you want,
but the new_boundary method is handy.
See below for the whole script.
>> multipart email with an attachment using TMail? This, incidentally,
would
>> make a great section on the Getting Start pages, as it''s
something a lot of
>> people do.
Feel like writing one up? :) I''ll put it up if you do :)
Mikel
----------
require ''rubygems''
require ''tmail''
require ''base64''
# setup general mail settings:
mail = TMail::Mail.new
mail.mime_version = "1.0"
mail.to = "mark at mackframework.com"
mail.from = "mark at mackframework.com"
mail.reply_to = mail.from
mail.subject = "hello world"
mail.set_content_type ''multipart'', ''mixed'',
{''boundary'' => TMail.new_boundary}
# Add the text/plain portion
text = TMail::Mail.new
text.mime_version = "1.0"
text.content_type = "text/plain"
text.body = "this is my plain text email"
mail.parts << text
# Add the text/html portion
html = TMail::Mail.new
text.mime_version = "1.0"
html.content_type = "text/html"
html.body = "this is my <b>HTML</b> email"
mail.parts << html
# Add an attachment
content = File.read("/Users/mikel/Pictures/MyPicture.jpg")
attachment = TMail::Mail.new
attachment.body = Base64.encode64(content)
attachment.transfer_encoding = "Base64"
attachment.content_type = "application/octet-stream"
attachment[''Content-Disposition''] = "attachment;
filename=MyPicture.jpg"
mail.parts << attachment
File.open(''testemail.eml'', ''w'') do |f|
f.puts mail.encoded
end
Setting:> mail.set_content_type ''multipart'', ''mixed'', {''boundary'' => > TMail.new_boundary}Gives me the same results. I''m using Apple Mail (Leopard), but I also see the same thing happening in GMail and Yahoo. The clients I''ve tested are all handling the attachments correctly, it''s the text & html parts that I don''t think it''s handling correctly. They''re all showing both, and not just one of them. Once I get this all worked out, I''ll be more than happy to write a tutorial on doing multipart messages and attachments. I''m always willing to give back. :) ------------------------------------------------------------------------------------------------- Mark Bates mark at mackframework.com http://www.mackframework.com http://api.mackframework.com/ http://github.com/markbates/mack On Jul 24, 2008, at 12:29 AM, Mikel Lindsaar wrote:> Dear Mark, > > Try setting: > > mail.set_content_type ''multipart'', ''mixed'', {''boundary'' => > TMail.new_boundary} > > At the top in the first ''mail'' block. You have to set the multipart > and mixed separately. You can set the boundary to whatever you want, > but the new_boundary method is handy. > > See below for the whole script. > >>> multipart email with an attachment using TMail? This, >>> incidentally, would >>> make a great section on the Getting Start pages, as it''s something >>> a lot of >>> people do. > > Feel like writing one up? :) I''ll put it up if you do :) > > Mikel > > ---------- > > require ''rubygems'' > require ''tmail'' > require ''base64'' > > # setup general mail settings: > mail = TMail::Mail.new > mail.mime_version = "1.0" > mail.to = "mark at mackframework.com" > mail.from = "mark at mackframework.com" > mail.reply_to = mail.from > mail.subject = "hello world" > mail.set_content_type ''multipart'', ''mixed'', {''boundary'' => > TMail.new_boundary} > > # Add the text/plain portion > text = TMail::Mail.new > text.mime_version = "1.0" > text.content_type = "text/plain" > text.body = "this is my plain text email" > mail.parts << text > > # Add the text/html portion > html = TMail::Mail.new > text.mime_version = "1.0" > html.content_type = "text/html" > html.body = "this is my <b>HTML</b> email" > mail.parts << html > > # Add an attachment > content = File.read("/Users/mikel/Pictures/MyPicture.jpg") > attachment = TMail::Mail.new > attachment.body = Base64.encode64(content) > attachment.transfer_encoding = "Base64" > attachment.content_type = "application/octet-stream" > attachment[''Content-Disposition''] = "attachment; > filename=MyPicture.jpg" > mail.parts << attachment > > File.open(''testemail.eml'', ''w'') do |f| > f.puts mail.encoded > end > _______________________________________________ > Tmail-talk mailing list > Tmail-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/tmail-talk
You need to bundle the 2 alternate body types into a parent part. Ie, the email should look something like this: irb(main):006:0> puts msg.to_mime.to_tree - #<Mime content_type="multipart/mixed"> |- #<Mime content_type="multipart/alternative"> | |- #<Mime content_type="text/plain"> | \- #<Mime content_type="text/html"> \- #<Mime content_type="application/octet-stream"> I''ve a patch somewhere that adds a similar "tree view" output to tmail objects which is helpful for debugging this stuff. On Thu, Jul 24, 2008 at 7:45 AM, Mark Bates <mark at mackframework.com> wrote:> Setting: > > mail.set_content_type ''multipart'', ''mixed'', {''boundary'' => >> TMail.new_boundary} >> > > Gives me the same results. > > I''m using Apple Mail (Leopard), but I also see the same thing happening in > GMail and Yahoo. The clients I''ve tested are all handling the attachments > correctly, it''s the text & html parts that I don''t think it''s handling > correctly. They''re all showing both, and not just one of them. > > Once I get this all worked out, I''ll be more than happy to write a tutorial > on doing multipart messages and attachments. I''m always willing to give > back. :) > > > ------------------------------------------------------------------------------------------------- > Mark Bates > mark at mackframework.com > http://www.mackframework.com > http://api.mackframework.com/ > http://github.com/markbates/mack > > > > On Jul 24, 2008, at 12:29 AM, Mikel Lindsaar wrote: > > Dear Mark, >> >> Try setting: >> >> mail.set_content_type ''multipart'', ''mixed'', {''boundary'' => >> TMail.new_boundary} >> >> At the top in the first ''mail'' block. You have to set the multipart >> and mixed separately. You can set the boundary to whatever you want, >> but the new_boundary method is handy. >> >> See below for the whole script. >> >> multipart email with an attachment using TMail? This, incidentally, would >>>> make a great section on the Getting Start pages, as it''s something a lot >>>> of >>>> people do. >>>> >>> >> Feel like writing one up? :) I''ll put it up if you do :) >> >> Mikel >> >> ---------- >> >> require ''rubygems'' >> require ''tmail'' >> require ''base64'' >> >> # setup general mail settings: >> mail = TMail::Mail.new >> mail.mime_version = "1.0" >> mail.to = "mark at mackframework.com" >> mail.from = "mark at mackframework.com" >> mail.reply_to = mail.from >> mail.subject = "hello world" >> mail.set_content_type ''multipart'', ''mixed'', {''boundary'' => >> TMail.new_boundary} >> >> # Add the text/plain portion >> text = TMail::Mail.new >> text.mime_version = "1.0" >> text.content_type = "text/plain" >> text.body = "this is my plain text email" >> mail.parts << text >> >> # Add the text/html portion >> html = TMail::Mail.new >> text.mime_version = "1.0" >> html.content_type = "text/html" >> html.body = "this is my <b>HTML</b> email" >> mail.parts << html >> >> # Add an attachment >> content = File.read("/Users/mikel/Pictures/MyPicture.jpg") >> attachment = TMail::Mail.new >> attachment.body = Base64.encode64(content) >> attachment.transfer_encoding = "Base64" >> attachment.content_type = "application/octet-stream" >> attachment[''Content-Disposition''] = "attachment; filename=MyPicture.jpg" >> mail.parts << attachment >> >> File.open(''testemail.eml'', ''w'') do |f| >> f.puts mail.encoded >> end >> _______________________________________________ >> Tmail-talk mailing list >> Tmail-talk at rubyforge.org >> http://rubyforge.org/mailman/listinfo/tmail-talk >> > > _______________________________________________ > Tmail-talk mailing list > Tmail-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/tmail-talk >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/tmail-talk/attachments/20080724/b09e0e40/attachment.html>
YES!! That''s it! Thanks so much! You just made my day. :) ------------------------------------------------------------------------------------------------- Mark Bates mark at mackframework.com http://www.mackframework.com http://api.mackframework.com/ http://github.com/markbates/mack On Jul 24, 2008, at 11:25 AM, charles wrote:> You need to bundle the 2 alternate body types into a parent part. > Ie, the email should look something like this: > > irb(main):006:0> puts msg.to_mime.to_tree > - #<Mime content_type="multipart/mixed"> > |- #<Mime content_type="multipart/alternative"> > | |- #<Mime content_type="text/plain"> > | \- #<Mime content_type="text/html"> > \- #<Mime content_type="application/octet-stream"> > > I''ve a patch somewhere that adds a similar "tree view" output to > tmail objects which is helpful for debugging this stuff. > > On Thu, Jul 24, 2008 at 7:45 AM, Mark Bates <mark at mackframework.com> > wrote: > Setting: > > mail.set_content_type ''multipart'', ''mixed'', {''boundary'' => > TMail.new_boundary} > > Gives me the same results. > > I''m using Apple Mail (Leopard), but I also see the same thing > happening in GMail and Yahoo. The clients I''ve tested are all > handling the attachments correctly, it''s the text & html parts that > I don''t think it''s handling correctly. They''re all showing both, and > not just one of them. > > Once I get this all worked out, I''ll be more than happy to write a > tutorial on doing multipart messages and attachments. I''m always > willing to give back. :) > > ------------------------------------------------------------------------------------------------- > > Mark Bates > mark at mackframework.com > http://www.mackframework.com > http://api.mackframework.com/ > http://github.com/markbates/mack > > > > On Jul 24, 2008, at 12:29 AM, Mikel Lindsaar wrote: > > Dear Mark, > > Try setting: > > mail.set_content_type ''multipart'', ''mixed'', {''boundary'' => > TMail.new_boundary} > > At the top in the first ''mail'' block. You have to set the multipart > and mixed separately. You can set the boundary to whatever you want, > but the new_boundary method is handy. > > See below for the whole script. > > multipart email with an attachment using TMail? This, incidentally, > would > make a great section on the Getting Start pages, as it''s something a > lot of > people do. > > Feel like writing one up? :) I''ll put it up if you do :) > > Mikel > > ---------- > > require ''rubygems'' > require ''tmail'' > require ''base64'' > > # setup general mail settings: > mail = TMail::Mail.new > mail.mime_version = "1.0" > mail.to = "mark at mackframework.com" > mail.from = "mark at mackframework.com" > mail.reply_to = mail.from > mail.subject = "hello world" > mail.set_content_type ''multipart'', ''mixed'', {''boundary'' => > TMail.new_boundary} > > # Add the text/plain portion > text = TMail::Mail.new > text.mime_version = "1.0" > text.content_type = "text/plain" > text.body = "this is my plain text email" > mail.parts << text > > # Add the text/html portion > html = TMail::Mail.new > text.mime_version = "1.0" > html.content_type = "text/html" > html.body = "this is my <b>HTML</b> email" > mail.parts << html > > # Add an attachment > content = File.read("/Users/mikel/Pictures/MyPicture.jpg") > attachment = TMail::Mail.new > attachment.body = Base64.encode64(content) > attachment.transfer_encoding = "Base64" > attachment.content_type = "application/octet-stream" > attachment[''Content-Disposition''] = "attachment; > filename=MyPicture.jpg" > mail.parts << attachment > > File.open(''testemail.eml'', ''w'') do |f| > f.puts mail.encoded > end > _______________________________________________ > Tmail-talk mailing list > Tmail-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/tmail-talk > > _______________________________________________ > Tmail-talk mailing list > Tmail-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/tmail-talk > > _______________________________________________ > Tmail-talk mailing list > Tmail-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/tmail-talk-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/tmail-talk/attachments/20080724/89a5905d/attachment-0001.html>
No problems - happy to help! On Thu, Jul 24, 2008 at 12:06 PM, Mark Bates <mark at mackframework.com> wrote:> YES!! That''s it! Thanks so much! You just made my day. :) > > > ------------------------------------------------------------------------------------------------- > Mark Bates > mark at mackframework.com > http://www.mackframework.com > http://api.mackframework.com/ > http://github.com/markbates/mack > > > > On Jul 24, 2008, at 11:25 AM, charles wrote: > > You need to bundle the 2 alternate body types into a parent part. Ie, the > email should look something like this: > > irb(main):006:0> puts msg.to_mime.to_tree > - #<Mime content_type="multipart/mixed"> > |- #<Mime content_type="multipart/alternative"> > | |- #<Mime content_type="text/plain"> > | \- #<Mime content_type="text/html"> > \- #<Mime content_type="application/octet-stream"> > > I''ve a patch somewhere that adds a similar "tree view" output to tmail > objects which is helpful for debugging this stuff. > > On Thu, Jul 24, 2008 at 7:45 AM, Mark Bates <mark at mackframework.com> > wrote: > >> Setting: >> >> mail.set_content_type ''multipart'', ''mixed'', {''boundary'' => >>> TMail.new_boundary} >>> >> >> Gives me the same results. >> >> I''m using Apple Mail (Leopard), but I also see the same thing happening in >> GMail and Yahoo. The clients I''ve tested are all handling the attachments >> correctly, it''s the text & html parts that I don''t think it''s handling >> correctly. They''re all showing both, and not just one of them. >> >> Once I get this all worked out, I''ll be more than happy to write a >> tutorial on doing multipart messages and attachments. I''m always willing to >> give back. :) >> >> >> ------------------------------------------------------------------------------------------------- >> Mark Bates >> mark at mackframework.com >> http://www.mackframework.com >> http://api.mackframework.com/ >> http://github.com/markbates/mack >> >> >> >> On Jul 24, 2008, at 12:29 AM, Mikel Lindsaar wrote: >> >> Dear Mark, >>> >>> Try setting: >>> >>> mail.set_content_type ''multipart'', ''mixed'', {''boundary'' => >>> TMail.new_boundary} >>> >>> At the top in the first ''mail'' block. You have to set the multipart >>> and mixed separately. You can set the boundary to whatever you want, >>> but the new_boundary method is handy. >>> >>> See below for the whole script. >>> >>> multipart email with an attachment using TMail? This, incidentally, >>>>> would >>>>> make a great section on the Getting Start pages, as it''s something a >>>>> lot of >>>>> people do. >>>>> >>>> >>> Feel like writing one up? :) I''ll put it up if you do :) >>> >>> Mikel >>> >>> ---------- >>> >>> require ''rubygems'' >>> require ''tmail'' >>> require ''base64'' >>> >>> # setup general mail settings: >>> mail = TMail::Mail.new >>> mail.mime_version = "1.0" >>> mail.to = "mark at mackframework.com" >>> mail.from = "mark at mackframework.com" >>> mail.reply_to = mail.from >>> mail.subject = "hello world" >>> mail.set_content_type ''multipart'', ''mixed'', {''boundary'' => >>> TMail.new_boundary} >>> >>> # Add the text/plain portion >>> text = TMail::Mail.new >>> text.mime_version = "1.0" >>> text.content_type = "text/plain" >>> text.body = "this is my plain text email" >>> mail.parts << text >>> >>> # Add the text/html portion >>> html = TMail::Mail.new >>> text.mime_version = "1.0" >>> html.content_type = "text/html" >>> html.body = "this is my <b>HTML</b> email" >>> mail.parts << html >>> >>> # Add an attachment >>> content = File.read("/Users/mikel/Pictures/MyPicture.jpg") >>> attachment = TMail::Mail.new >>> attachment.body = Base64.encode64(content) >>> attachment.transfer_encoding = "Base64" >>> attachment.content_type = "application/octet-stream" >>> attachment[''Content-Disposition''] = "attachment; filename=MyPicture.jpg" >>> mail.parts << attachment >>> >>> File.open(''testemail.eml'', ''w'') do |f| >>> f.puts mail.encoded >>> end >>> _______________________________________________ >>> Tmail-talk mailing list >>> Tmail-talk at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/tmail-talk >>> >> >> _______________________________________________ >> Tmail-talk mailing list >> Tmail-talk at rubyforge.org >> http://rubyforge.org/mailman/listinfo/tmail-talk >> > > _______________________________________________ > Tmail-talk mailing list > Tmail-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/tmail-talk > > > > _______________________________________________ > Tmail-talk mailing list > Tmail-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/tmail-talk > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/tmail-talk/attachments/20080724/6aa24df9/attachment.html>
On Fri, Jul 25, 2008 at 1:25 AM, charles <aquasync at gmail.com> wrote:> irb(main):006:0> puts msg.to_mime.to_tree > - #<Mime content_type="multipart/mixed"> > |- #<Mime content_type="multipart/alternative"> > | |- #<Mime content_type="text/plain"> > | \- #<Mime content_type="text/html"> > \- #<Mime content_type="application/octet-stream"> > > I''ve a patch somewhere that adds a similar "tree view" output to tmail > objects which is helpful for debugging this stuff.Gimmie, I''ll put it into the tree. That looks useful. -- http://lindsaar.net/ Rails, RSpec and Life blog....
Hi Mikel,
I''m currently monkey patching it in, with some code like:
module TMail
class Mail
TO_TREE_INSPECT_DEFAULT = proc { |node| "#<Mime
content_type=#{node.content_type.inspect}>" }
def to_tree io='''', &inspect
inspect ||= TO_TREE_INSPECT_DEFAULT
io << "- #{inspect[self]}\n"
recurse = proc do |node, prefix|
if node.multipart?
node.parts.each_with_index do |child, i|
a, b = i == parts.length - 1 ? ["\\", '' ''] :
[''|'', ''| '']
io << "#{prefix + a}- #{inspect[child]}\n"
recurse.call child, prefix + b
end
end
end
recurse.call self, '' ''
io
end
end
end
__END__
Feel free to redefine TO_TREE_INSPECT_DEFAULT as you see fit (or just
switch it to :inspect.to_proc if you feel like making the default
TMail::Mail#inspect a bit easier on the eyes). Thats just there for
compatability with the custom message class I''m trying to replace with
TMail.
Usage is something like this to return a string:
irb(main):133:0* puts mail.to_tree
- #<Mime content_type="multipart/mixed">
|- #<Mime content_type="multipart/alternative">
| |- #<Mime content_type="text/plain">
| \- #<Mime content_type="text/html">
\- #<Mime content_type="application/octet-stream">
=> nil
Or you can stream directly to some IO object, and optionally override
the string formation:
irb(main):174:0> mail.to_tree(STDOUT) { |m| "#{m.content_type}
(#{m.inspect[0, 50]}...)" }
- multipart/mixed (#<TMail::Mail port=#<TMail::StringPort:id=0x165ea0...)
|- multipart/alternative (#<TMail::Mail
port=#<TMail::StringPort:id=0x164d70...)
| |- text/plain (#<TMail::Mail port=#<TMail::StringPort:id=0x16206e...)
| \- text/html (#<TMail::Mail port=#<TMail::StringPort:id=0x161f78...)
\- application/octet-stream (#<TMail::Mail
port=#<TMail::StringPort:id=0x164369...)
=> #<IO:0x2846af0>
On Thu, Jul 24, 2008 at 8:19 PM, Mikel Lindsaar <raasdnil at gmail.com>
wrote:>
> On Fri, Jul 25, 2008 at 1:25 AM, charles <aquasync at gmail.com>
wrote:
> > irb(main):006:0> puts msg.to_mime.to_tree
> > - #<Mime content_type="multipart/mixed">
> > |- #<Mime content_type="multipart/alternative">
> > | |- #<Mime content_type="text/plain">
> > | \- #<Mime content_type="text/html">
> > \- #<Mime content_type="application/octet-stream">
> >
> > I''ve a patch somewhere that adds a similar "tree
view" output to tmail
> > objects which is helpful for debugging this stuff.
>
> Gimmie, I''ll put it into the tree. That looks useful.
>
> --
> http://lindsaar.net/
> Rails, RSpec and Life blog....
> _______________________________________________
> Tmail-talk mailing list
> Tmail-talk at rubyforge.org
> http://rubyforge.org/mailman/listinfo/tmail-talk
Dear Charles, Thanks for that, I''ll get it in. My next task for TMail is getting 1.9 compatibility nailed. 2.0 is going to be a re-write. I want to simplify a _lot_ of things in TMail. Anyone who is interested in helping, send me a yo! It will not be hard and heavy, TMail is really needed for Ruby, and the current implementation is a bit dated now. Anyway, thanks for the code. Mikel
I''d be interested in helping out with 2.0. Big rewrites seem risky though, might be better if we can just push the code gradually in the right direction. What are the main things you want to change? I''d like to clean up my IO patches, and replace the (at least it seems to me?) unnecessary "port" abstraction with plain IO objects. Example use case, is to create a TMail object from an arbitrary IO handle, from an email in a zip (eg zip/zipfilesystem), or wherever. Maybe a first step is to introduce an IOPort class. After that, I''d like to see tmail perform better with large emails - eg not holding an entire 20M attachment in memory raw, and base64 encoded, but using streaming and filters for encoding/decoding. On Sat, Jul 26, 2008 at 8:26 AM, Mikel Lindsaar <raasdnil at gmail.com> wrote:> Dear Charles, > > Thanks for that, I''ll get it in. > > My next task for TMail is getting 1.9 compatibility nailed. > > 2.0 is going to be a re-write. I want to simplify a _lot_ of things > in TMail. Anyone who is interested in helping, send me a yo! It will > not be hard and heavy, TMail is really needed for Ruby, and the > current implementation is a bit dated now. > > Anyway, thanks for the code. > > Mikel > _______________________________________________ > Tmail-talk mailing list > Tmail-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/tmail-talk >