How to use resources in Mailer?

I'm having problems using any form of asset pipeline in my inbox, whether it be Mailer itself or a view.

As a result, an empty src image tag is also created.

<%= image_tag "emails/header-general.png" %> 

An empty image tag is as follows:

img alt = "General Title"

The following form of attaching a file to a model and using it in a view gives a blank image.

 attachments.inline['header.jpg'] = 'emails/header-general.png' ... <%= image_tag attachments['header.png'] %> 

I checked the path and even tried with several paths and so on, but no luck. Please help. Any form of including an image in a letter will be helpful.

Here is the production version.

 Xenium::Application.configure do # Settings specified here will take precedence over those in config/application.rb # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turned on config.consider_all_requests_local = false config.action_controller.perform_caching = true # Disable Rails static asset server (Apache or nginx will already do this) config.serve_static_assets = false # Compress JavaScripts and CSS config.assets.compress = true # Choose the compressors to use config.assets.js_compressor = :yui config.assets.css_compressor = :yui # Don't fallback to assets pipeline if a precompiled asset is missed config.assets.compile = true # Generate digests for assets URLs config.assets.digest = true # Defaults to Rails.root.join("public/assets") # config.assets.manifest = YOUR_PATH # Specifies the header that your server uses for sending files # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true # See everything in the log (default is :info) config.log_level = :fatal # Use a different logger for distributed setups # config.logger = SyslogLogger.new # Use a different cache store in production config.cache_store = :mem_cache_store # Enable serving of images, stylesheets, and JavaScripts from an asset server #config.action_controller.asset_host = "http://asset.xenium.bg" # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) # config.assets.precompile += %w( search.js ) # Disable delivery errors, bad email addresses will be ignored config.action_mailer.raise_delivery_errors = true #config.action_mailer.perform_deliveries = true config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :address => "localhost", :port => 25, :domain => 'xenium.bg', #:user_name => '<username>', #:password => '<password>', #:authentication => 'plain', :enable_starttls_auto => false } # Enable threaded mode # config.threadsafe! # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation can not be found) config.i18n.fallbacks = true # Send deprecation notices to registered listeners config.active_support.deprecation = :notify end 

Thanks!

+6
source share
2 answers

In Section 2.3.3 Creating Inline Attachments , to create an inline attachment, you will do the following:

 attachments.inline['image.jpg'] = File.read('/path/to/image.jpg') 

So in your case it should be

 attachments.inline['header.jpg'] = File.read("#{Rails.root}/app/assets/images/emails/header-general.png" 
+4
source

set config.action_controller.asset_host and config.action_mailer.asset_host and this works well.

 config.action_mailer.asset_host = URL from where pick image <%= image_tag image_path('logo.png') %> 
+1
source

Source: https://habr.com/ru/post/898159/


All Articles