嵌入式图像与红宝石邮件宝石 [英] inline images with ruby mail gem

查看:149
本文介绍了嵌入式图像与红宝石邮件宝石的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,如果我缺少一本好文章,但是我找不到一个很好的示例,说明如何将ruby与邮件gem一起使用内联图像(我没有使用RoR) 我能找到的最佳示例是此处 ,但我不知道.cid方法的来源.

Sorry if I'm missing a good article, but I can't find a good example on how to use inline images using ruby with the mail gem (I'm not using RoR) The best example I could find is here, but I don't understand where the .cid method comes from.

这是上述文章的摘录,其中使用了.cid方法.

here's an excerpt from the above mentioned post where the .cid method is used.

html_part do
    content_type 'text/html; charset=UTF-8'
    body "<img width=597 height=162 id='Banner0' src='cid:#{pic.cid}'>"
end

我可以使用邮件gem,它可以将图像作为附件发送,但是我需要将它们显示在电子邮件中,而无需打开附件.

I have the mail gem working and it can send images as attachments but I need them to be displayed inside the email, without having the need to open attachments.

推荐答案

邮件" gem ist维护得很好,因此对

The Mail gem ist quite well maintained, so it really helps to look into the documentation. Your provided snipped misses an integral part: the definition of pic:

pic = attachments['banner.png']

有了这些信息,您可以在 attachments 上轻松找到文档,这将产生此信息位:

With this information, you can easily find the documentation on attachments, which will yield this bit:

您还可以搜索特定的附件:

You can also search for specific attachments:

# By Filename
mail.attachments['filename.jpg']   #=> Mail::Part object or nil

Mail::Part 的文档中,您将找到(遗憾的是,此方法没有记录,但是很容易推断出"cid"代表内容ID").

(sadly, this method is not documented, but it's easy to infer that "cid" stands for "content id").

最后, RFC2557 定义了CID URI的用法,以识别和引用封装的文档(例如图像) ).这是

Finally, RFC2557 defines the usage of CID URIs to identify and reference encapsulated documents (such as images) within emails. This is where

body "<img ... src='cid:...'>"

来自.

这篇关于嵌入式图像与红宝石邮件宝石的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆