I'm trying to paste images into email. The problem is emails comming without images inside
我想把图片粘贴到电子邮件中。问题是电子邮件中没有图片
development.rb
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.
我哪里做错了?如果你需要更多的信息,请询问。
4 个解决方案
#1
11
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
确保设置了config.action_controller。asset_host和config.action_mailer.asset_host
#2
5
You're sending emails from localhost:3000
, which isn't publicly available (and limited to your machine only).
您正在从localhost:3000发送电子邮件,这不是公开的(并且仅限于您的机器)。
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.
使用像ngrok这样的服务来公开您的本地域。
Once done, be sure to replace config.action_mailer.asset_host = 'http://localhost:3000'
一旦完成,请确保替换config.action_mailer。asset_host = ' http://localhost:3000 '
with the ngrok URL (something like config.action_mailer.asset_host = 'http://<xxx>.ngrok.com'
)
使用ngrok URL(类似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?
此外,在视图文件中,您必须确保为映像指定了绝对url(而不仅仅是相对路径)。您可以在这里阅读更多:如何在Rails 3.1中获得资产的绝对URL ?
#3
1
If you use the
如果你使用
image_url('e-mail-logo.png')
instead of
而不是
image_path()
it will render the absolute path to the image, which should work. The internal path to the image is meaningless in the context of the message.
它将呈现图像的绝对路径,这应该是可行的。在消息的上下文中,映像的内部路径是没有意义的。
#4
1
I agree with Utsav Kesharwani. I recently faced the same problem. As the localhost is not publicly available, you cannot access images of localhost.
我同意尤察夫·卡夏瓦尼的观点。我最近也遇到了同样的问题。由于localhost不是公共可用的,所以无法访问localhost的图像。
So, One practical solution to this problem can be to upload your images to cloud and accessing them when you want to display those images.
因此,解决这个问题的一个切实可行的解决方案是将您的图像上载到云上,并在您想要显示这些图像时访问它们。
I personally prefer Cloudinary -- A cloud-based service that provides an end-to-end image management solution including uploads, storage, manipulations, optimizations and delivery.
我个人更喜欢cloud-一个基于云的服务,它提供端到端图像管理解决方案,包括上传、存储、操作、优化和交付。
You can refer to Cloudinary documentation for rails: http://cloudinary.com/documentation/rails_integration#getting_started_guide
您可以参考rails的Cloudinary文档:http://cloudinary.com/documentation/rails_integration#getting_started_guide。
I hope this helps.
我希望这可以帮助。
#1
11
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
确保设置了config.action_controller。asset_host和config.action_mailer.asset_host
#2
5
You're sending emails from localhost:3000
, which isn't publicly available (and limited to your machine only).
您正在从localhost:3000发送电子邮件,这不是公开的(并且仅限于您的机器)。
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.
使用像ngrok这样的服务来公开您的本地域。
Once done, be sure to replace config.action_mailer.asset_host = 'http://localhost:3000'
一旦完成,请确保替换config.action_mailer。asset_host = ' http://localhost:3000 '
with the ngrok URL (something like config.action_mailer.asset_host = 'http://<xxx>.ngrok.com'
)
使用ngrok URL(类似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?
此外,在视图文件中,您必须确保为映像指定了绝对url(而不仅仅是相对路径)。您可以在这里阅读更多:如何在Rails 3.1中获得资产的绝对URL ?
#3
1
If you use the
如果你使用
image_url('e-mail-logo.png')
instead of
而不是
image_path()
it will render the absolute path to the image, which should work. The internal path to the image is meaningless in the context of the message.
它将呈现图像的绝对路径,这应该是可行的。在消息的上下文中,映像的内部路径是没有意义的。
#4
1
I agree with Utsav Kesharwani. I recently faced the same problem. As the localhost is not publicly available, you cannot access images of localhost.
我同意尤察夫·卡夏瓦尼的观点。我最近也遇到了同样的问题。由于localhost不是公共可用的,所以无法访问localhost的图像。
So, One practical solution to this problem can be to upload your images to cloud and accessing them when you want to display those images.
因此,解决这个问题的一个切实可行的解决方案是将您的图像上载到云上,并在您想要显示这些图像时访问它们。
I personally prefer Cloudinary -- A cloud-based service that provides an end-to-end image management solution including uploads, storage, manipulations, optimizations and delivery.
我个人更喜欢cloud-一个基于云的服务,它提供端到端图像管理解决方案,包括上传、存储、操作、优化和交付。
You can refer to Cloudinary documentation for rails: http://cloudinary.com/documentation/rails_integration#getting_started_guide
您可以参考rails的Cloudinary文档:http://cloudinary.com/documentation/rails_integration#getting_started_guide。
I hope this helps.
我希望这可以帮助。