What is the right way to embed image into email using Rails?

I combined the answer from Oksana with a custom helper approach and got the following to work quite nicely. app/helpers/email_helper.rb module EmailHelper def email_image_tag(image, **options) attachments[image] = File.read(Rails.root.join(“app/assets/images/#{image}”)) image_tag attachments[image].url, **options end end app/mailers/base_mailer.rb class BaseMailer < ActionMailer::Base helper(EmailHelper) end app/mailers/my_mailer.rb class MyMailer < BaseMailer def send_my_mail(email) mail to: email, subject: “My Subject” end end … Read more

How to test ActionMailer deliver_later with rspec

If I understand you correctly, you could do: message_delivery = instance_double(ActionMailer::MessageDelivery) expect(ServiceMailer).to receive(:new_user).with(@user).and_return(message_delivery) allow(message_delivery).to receive(:deliver_later) The key thing is that you need to somehow provide a double for deliver_later.

How to define a reply-to address?

Two ways: class Notifications < ActionMailer::Base default :from => ‘your_app@your_domain.com’, :reply_to => ‘some_other_address@your_domain.com’ end Or: class Contacts < ActionMailer::Base def new_contact mail( :to => ‘somebody@some_domain.com’, :from => ‘your_app@your_domain.com’, :reply_to => ‘someone_else@some_other_domain.com’) end end Or you can mix the two approaches. I’m sure there are even more ways to do this.

Rails ActionMailer – format sender and recipient name/email address

If you are taking user input for name and email, then unless you very carefully validate or escape the name and email, you can end up with an invalid From header by simply concatenating strings. Here is a safe way: require ‘mail’ address = Mail::Address.new email # ex: “john@example.com” address.display_name = name.dup # ex: “John … Read more

How do I set up email confirmation with Devise?

1. Make sure you include confirmable in Model.devise call class User < ActiveRecord::Base devise :database_authenticatable, :confirmable … end 2. Make sure you add confirmable to the user migration create_table :users do |t| t.database_authenticatable t.confirmable … end If you’re using devise 2.0+ this fails because devise no longer provides migration helpers, and so t.confirmable raises an … Read more

Heroku/devise – Missing host to link to! Please provide :host parameter or set default_url_options[:host]

You need to add this to your environment.rb config.action_mailer.default_url_options = { :host => ‘localhost’ } Make sure you change host to your production url and keep it localhost for development. This is for the mailer, it needs a default email to send out notices such as confirmations etc… You should check the logs on the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)