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?
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') %>
just run rails generate devise:views
and edit template in app/views/devise/mailer/reset_password_instructions.html.erb
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With