Reputation: 472
I want to add attachment to email sent on reseting password by devise (logo image) and also I want to use user's locale to localize email text. Can anybody help and tell me what to override to do this?
Upvotes: 7
Views: 3952
Reputation: 3699
I'm using devise 4.3 for rails 5 app. Additional argument is required.
def reset_password_instructions(record, token, opts={})
attachments.inline['logo.png'] = File.read("#{Rails.root}/app/assets/images/logo.png")
super(record, token, opts)
end
Upvotes: 2
Reputation: 957
You need to add the logo image as an attachment.
To do so, follow the instructions in the link to override the default Devise::Mailer: https://github.com/plataformatec/devise/wiki/How-To:-Use-custom-mailer
Then, add the attachment using attachments.inline['logo.png']=
:
def reset_password_instructions(record, opts={})
attachments.inline['logo.png'] = File.read('app/assets/images/logo.png')
super(record, opts)
end
And in the view you can use attachments['logo.png'].url
:
<%= image_tag(attachments['logo.png'].url, alt: 'Logo') %>
Upvotes: 7
Reputation: 24617
just run rails generate devise:views
and edit template in app/views/devise/mailer/reset_password_instructions.html.erb
Upvotes: 3