trix icon indicating copy to clipboard operation
trix copied to clipboard

Using Trix as an editor for email content

Open maxwell opened this issue 3 years ago • 4 comments

I was wondering if anyone had any experience with using data produced from a Trix field to be uses as the content of an HTML email.

Since, styling and dom element support is pretty rough in emails, I was wondering if its just a lost cause to try to use trix for this use case. I dont need complex layout capabilities, but giving users a section to customize, include images, et al would be really awesome.

maxwell avatar Jun 29 '22 20:06 maxwell

http://hey.com uses Trix and is an email provider. I use Hey, so I have daily experience with data produced from a Trix field to be used as content in an HTML email.

Merovex avatar Jul 05 '22 11:07 Merovex

Trix, afaik, doesn't do anything special with your HTML, underneath the hood is plain 'ol HTML. Any email provider will take your HTML and parse it to their needs.

I've used Trix and Rails to create an email solution for one of my apps. Sending is easy, it's the receiving that's problematic if you care about format.

The problem is that the content received by ActionMailbox is obviously not compatible with Trix, so you need parsers for each major provider, Outlook, Gmail, and Apple's Mail. Or, if you know regex, you can create one parser to rule them all.

pacMakaveli avatar Aug 03 '22 08:08 pacMakaveli

@maxwell I use it in my app. Users create emails using trix and if they have images I replace the attachment for an image. Like this

def body
    doc = Nokogiri::HTML(params[:email].content.body.to_html)
    doc.css('action-text-attachment').each do |attachment|
      img = doc.create_element 'img'
      img['src'] = attachment['url']
      img['style'] = 'max-width: 100%;'
      attachment.replace img
    end
    doc.to_s
  end

silva96 avatar Aug 08 '22 20:08 silva96

Hi @pacMakaveli, our team is having a hard time figuring out how to parse incoming HTML emails on the backend to be compatible with Trix. I work on the front end and inserting them after serialization produces an absolute mess. Please can you share a bit on how these parsers would work?

dayang4321 avatar Jan 24 '23 04:01 dayang4321