您可以通过几种方式做到这一点。一种方法是直接定义附件:
encoded_content = SpecialEncode(File.read('/path/to/filename.jpg'))
attachments['filename.jpg'] = {:mime_type => 'application/x-gzip',
:encoding => 'SpecialEncoding',
:content => encoded_content }
并将文件名替换为您的文件,或者您可以使用附件的内联定义,如下所示:
或者在你的邮件程序中定义:
def welcome
attachments.inline['image.jpg'] = File.read('/path/to/image.jpg')
end
并在视图中:
<p>Hello there, this is our image</p>
<%= image_tag attachments['image.jpg'].url, :alt => 'My Photo',
:class => 'photos' %>
您可以在此处找到如何创建附件的参考:http://guides.rubyonrails.org/action_mailer_basics.html http://guides.rubyonrails.org/action_mailer_basics.html
但如果您使用 Heroku,您可能会遇到一些困难 - 您可以在这里阅读相关内容:ActionMailer - 如何添加附件? https://stackoverflow.com/questions/4360377/actionmailer-how-to-add-an-attachment
EDIT:
是的,您提出的问题和代码让我困惑什么是真正的问题。我现在相信您正在寻找这个:
mail_to "[email protected] /cdn-cgi/l/email-protection"
寻找参考:http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-mail_to http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-mail_to
如果您想预先填充正文,您可以在这里找到一些内容将 mail_to 与块一起使用 (mail_to ... do) https://stackoverflow.com/questions/7062407/using-mail-to-with-a-block-mail-to-do
在这里添加图片,也许你可以找到有用的东西Rails:在 mail_to 链接中包含 html https://stackoverflow.com/questions/4224504/rails-include-html-in-a-mail-to-link
我刚刚从我的脑海中输入了一段代码,我希望某种附加方式可能会起作用:
<%= mail_to("[email protected] /cdn-cgi/l/email-protection", image_tag("email.gif")) %>
我还没有尝试过所有这些,但我希望有些东西会起作用,或者引导你朝着好的方向发展