Patrick Collins
2007-Feb-09 04:48 UTC
trying to add html email capabilites (multi-part)...
I am trying to achieve sending a multipart newsletter so that people with html mail capabilities will see a glorified version of the email, and people like me who use pine will see plaintext. As of right now, I have: part "text/plain" do |p| if newsletter.newsletter.length == 0 p.body = "" else greeting = contact.first_name || ''Hello'' p.body = "#{greeting},\n\n" + newsletter.newsletter end end part "text/html" do |p| if newsletter.newsletter.length == 0 p.body = "" else greeting = contact.first_name || ''Hello'' p.body = "<!DOCTYPE HTML PUBLIC ''-//W3C//DTD HTML 4.01 Transitional//EN''><html><p> #{greeting},</p><p>" + newsletter.newsletter + "</p></div></body></html>" end end newsletter.attachments.each do |attachment| part attachment.content_type do |p| p.body = attachment.contents p.filename = attachment.filename p.transfer_encoding = ''base64'' end end rescue return false end return true end end however this is rendering HTML as an "attachment".. I am very unclear about how this is supposed to work, but I just know if I look at an email sent by Yahoo for example, their html mail shows up as plaintext, and I see a separate index that I can select in pine which will then attempt to launch a browser to view it... And if I look at this same email in a browser, it appears as a nice clean html version. However when looking at my own email in pine, it displays both side by side as PART1: plaintext and PART2: HTML... This is the same behavior when viewing in a browser as you can see here: http://www.collinatorstudios.com/www/budokonmail2.png I tried changing this to have: part :content_type => "text/html", :body => render_message("signup-as-html", :account => recipient) as I saw on several websites that were giving tutorial discussions on html email within ruby on rails, bowever this did not work... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Patrick Collins wrote:> I am trying to achieve sending a multipart newsletter so that people > with html mail capabilities will see a glorified version of the email, > and people like me who use pine will see plaintext.I think you are trying too hard. You can create an rhtml file for every "part" and action mailer will pick them up automagically. With these views: * signup_notification.text.plain.rhtml * signup_notification.text.html.rhtml * signup_notification.text.xml.rxml * signup_notification.text.x-yaml.rhtml Mailer.deliver_signup_notification will send an email with 4 parts with the content types of: * text/plain * text/html * text/xml * text/x-yaml http://api.rubyonrails.com/classes/ActionMailer/Base.html As a bonus you model stays dead simple with just the info it needs and no more. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Patrick Collins
2007-Feb-09 07:40 UTC
Re: trying to add html email capabilites (multi-part)...
Alex Wayne wrote:>You can create an rhtml file for every "part" and action mailer will pick them up automagically.Forgive me, but I am really new at ruby on rails.. This current app code was written by a developer and I am trying to add HTML capabilities to it myself. The app is a contact hub which you select a large number of email addresses and then send a newsletter to them. You go to a specific file and type into a standard html form text box, and then the email gets sent.. The text in the box is what was described in my code "newsletter.newsletter"... So I was imagining since plaintext works, the easiest thing would be to place whatever the contents of newsletter.newsletter into html data... Of course I also realized that I need a way to convert carriage returns within newsletter.newsletter to "<br>". However, if you have a better way to go, to get newsletter.newsletter to become an actual html and plaintext file, I would love to know how to do this. Thanks in advance. -patrick -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---