0

When a User is connected and creates a new Vacation, an email must be send to chosen validator of the Vacation. Here's my current ActionMailer:

class UserNotifier < ActionMailer::Base
  default from: "from@example.com"

  def send_validation_vacation_email(user, receiver, vacation)
   @user = user
   @receiver = receiver
   @vacation = vacation
   mail(:to => receiver.email, :subject => 'Blabla')
  end
end

As you can see, I'm able to get all the data I need. However, I don't know how to setup the ActionMailer so that the sender address can be changed.

Do I need to connect the ActionMailer to the User model?

Grégoire Borel
  • 1,880
  • 3
  • 33
  • 55
  • 3
    take a look at http://stackoverflow.com/a/957473/1380867 and just add `:from => 'sender@email.com'` to the mail – MZaragoza Dec 17 '14 at 16:28

1 Answers1

1

You can use from in specific method/mailer where you want to change sender address(do not want to use default sender).
Try this one:

mail(:to => receiver.email, :subject => 'Blabla', :from => user.email)

Ashutosh Tiwari
  • 984
  • 6
  • 16
  • Thanks, but the email doesn't seem to be sent. I tried to email myself and didn't receive anything. Do I need to setup some parameters in the ActionMailer configuration? – Grégoire Borel Dec 17 '14 at 16:43
  • you need to do few settings in respective env files. take a look at here http://www.xyzpub.com/en/ruby-on-rails/3.2/konfiguration_email_server.html – Ashutosh Tiwari Dec 17 '14 at 16:55
  • Thanks. What are the username and password? Those of the User or the server? I don't know much about the network side, sorry. – Grégoire Borel Dec 17 '14 at 17:01
  • Use your email(gamil) as username and you gmail password for password and remove the domain line.and do as the described in the links provided above. – Ashutosh Tiwari Dec 17 '14 at 17:04