trix icon indicating copy to clipboard operation
trix copied to clipboard

Send Trix HTML to email

Open Immortalpk opened this issue 7 years ago • 7 comments

I am using figure tag as attachment for below functionality.

  1. Image
  2. Video
  3. Mentioning using tribute.js

I am storing the trix html directly to mysql db and at same time we are sending the same content to mail. but mail formating is not coming good as its not taking attachment properly. also, I have lots of css to make the editor content good.

As, as per my exploration basecamp is not sending figure tag over mail but its showing in in trix editor.

is there any way to convert trix editor html to normal span format html,

@sstephenson @javan , Please respond.

  • Trix version: Latest
  • Browser name and version: Chrome Version 73.0.3683.103 (Official Build) (64-bit)
  • Operating system: OSX

Immortalpk avatar Apr 25 '19 12:04 Immortalpk

@Immortalpk just handle this with server-side code, it's what we do in our product. We've got no issue with sending emails w/ images using HTML generated via Trix.

jessehanley avatar May 02 '19 00:05 jessehanley

If I am inspecting basecamp mail. its creating different structure while comparing it with stored trix HTML.

Do, I have to add handler to convert trix HTML to pure HTML ?

Immortalpk avatar May 02 '19 07:05 Immortalpk

I don’t think this is really relevant to the Trix project itself, unless someone wants to contribute documentation on the topic. As @jessehanley said, the best solution here is probably to do some processing of the HTML server-side before sending the email to convert to email-friendly styling.

lachlanjc avatar Jul 09 '19 06:07 lachlanjc

This issue has been automatically marked as stale after 90 days of inactivity. It will be closed if no further activity occurs.

stale[bot] avatar Oct 07 '19 07:10 stale[bot]

Hi! How did you solve this? @Immortalpk

gabrieelgomez avatar Jun 07 '21 22:06 gabrieelgomez

Hi! How did you solve this? @Immortalpk

Assuming you save the content using has_rich_text :content in the Post model

# somewhere call SomeMailer.with(post_id: 123).some_email_action.deliver
# then in SomeMailer

def some_email_action
  dirty_content = Post.find(params[:post_id]).content.body.to_html
  clean_content = clean(dirty_content)
  mail(to: '[email protected]', from: '[email protected]', body: clean_content, content_type: 'text/html')
end

def clean(dirty_content)
    doc = Nokogiri::HTML(dirty_content)
    doc.css('action-text-attachment').each do |attachment|
      img = doc.create_element 'img'
      img['src'] = "https://domain.com#{attachment['url']}"
      attachment.replace img
    end
    doc.to_s
  end

silva96 avatar Jul 08 '22 19:07 silva96

I had the same issue in Trix I would have a figure element with a img tag inside but once processed it becomes an active-storage-attachment. the fix was to call .to_trix_html on the ActionText::Content

Laassari avatar Oct 28 '22 15:10 Laassari