Question

I am trying to send an email to the event administrator, after the user confirms.

See: Rails: Devise: Sending an email after user comfirms registration

I wrote an EventMailer class as follows:

class EventMailer < ActionMailer::Base
  @user = User

  @host_name = "localhost:3000" if Rails.env.development?
  @host_name = "test.com" if Rails.env.test?
  @host_name = "production.com" if Rails.env.production?

 def self.send_email_to_admin
   @@smtp_settings = { #override default smtp settings since I'm using a difference sender
     :address => "smtp.gmail.com",
     :port => 587,
     :domain => @host_name,

     :authentication => "plain",
     :enable_starttls_auto_=> true,
     :user_name => ENV["ORG_FROM"],
     :password => ENV["ORG_FROM_PWD"],
     :to => ADMIN_RECIPIENTS
     #ADMIN_RECIPIENTS is defined elsewhere
   }
   mail(:subject => "Invite request received from " + @user.first.to_s + " " + @user.last.to_s)
 end
end

When users register, they receive a registration link. When they click on that link, they get the following error message:

undefined method `mail' for EventMailer:Class

app/mailers/event_mailer.rb:20:in `send_email_to_admin'
app/controllers/confirmations_controller.rb:11:in `show'

Any ideas?

EDIT:

The solution is to move both the :to and :from inside the mail nethod

Was it helpful?

Solution

Try moving :to => DENT_ADMIN_RECIPIENTS into the mail method:

mail(:to => DENT_ADMIN_RECIPIENTS, :subject => "Invite request received from " + @user.first.to_s + " " + @user.last.to_s)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top