I'm trying to paste images into email. The problem is emails comming without images inside
development.rb
config.action_mailer.default_url_options = { :host => 'localhost:3000', :only_path => false } config.action_mailer.raise_delivery_errors = false config.action_mailer.asset_host = 'http://localhost:3000'
view file:
<div class="image"> <%= image_tag image_path('email-logo.png') %> </div>
Where did I make a mistake? Please ask if you need more information.
try
<div class="image"> <%= image_tag('email-logo.png') %> </div>
Make sure you set config.action_controller.asset_host
and config.action_mailer.asset_host
You're sending emails from localhost:3000
, which isn't publicly available (and limited to your machine only).
You have to expose your local environment, so that images can be downloaded in your mail client.
Use service like ngrok to expose your local domain.
Once done, be sure to replace config.action_mailer.asset_host = 'http://localhost:3000'
with the ngrok URL (something like config.action_mailer.asset_host = 'http://<xxx>.ngrok.com'
)
Also, in your view file, you'll have to ensure that you specify the absolute url for the image (and not just the relative path). You can read more on that here: How do I get an absolute URL for an asset in Rails 3.1?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With