Eingebettete Anhänge
(Inline Attachments)
Für
Inline
Attachments in HTML-E-Mails muss man die Methode
inline
beim Aufruf von
attachments
benutzen. In unserem Beispielcontroller
app/mailers/notification.rb
:
class Notification < ActionMailer::Base
default from: "from@example.com"
def new_account(user)
@user = user
attachments.inline['rails.png'] = File.read("#{Rails.root}/app/assets/images/rails.png")
mail(:to => user.email,
:subject => "The new account #{user.name} is active.")
end
end
In der HTML-E-Mail kann auf den Hash
attachments[]
per
image_tag
zugegriffen werden. In unserem
Beispiel sähe die
app/views/notification/new_account.html.erb
so
aus:
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
</head>
<body>
<%= image_tag attachments['rails.png'].url, :alt => 'Rails Logo' %>
<p>Hello <%= @user.name %>,</p>
<p>your new account is active.</p>
<p><i>Have a great day!</i></p>
<p>A Robot</p>
</body>
</html>