I'm implementing mailer, but I can't send mail.

Asked 2 years ago, Updated 2 years ago, 31 views

Currently, I am thinking of using mailer so that when I go to a certain page, the mail will be sent.However, the controller is not configured well, so it cannot be sent.If anyone knows, please let me know.

Enter a description of the image here
Enter a description of the image here

controller/tourist/done.controller.rb

def done
  TouristMailer.tourist_payment_mail(self).deliver_now
end

config/environment/development.rb

config.consider_all_requests_local=true
config.action_controller.perform_caching=false
config.action_mailer.delivery_method=: smtp
config.action_mailer.smtp_settings={
     address: 'smtp.gmail.com',
     port:587,
     domain: 'smtp.gmail.com',
     user_name: '******@g mail.com',
     password: '**********',
     authentication: 'plain',
     enable_starttls_auto —true
   }

application_mailer.rb

class ApplicationMailer<ActionMailer::Base
  default from: "******@g mail.com"
  layout'mailer'
end

model/tourist.rb

class Tourist <ActiveRecord::Base
  # Include default device modules.Others available are:
  # :confirmable, :lockable, :timeoutable and :mniauthable
  after_create —send_welcome_mail

  def send_welcome_mail
     TouristMailer.tourist_welcome_mail(self).deliver_now
  end

  default_payment_mail
     TouristMailer.tourist_payment_mail(self).deliver_now
  end

  has_many —Guiders

  device:database_authenticatable, :registerable,
           :recoverable, :rememberable, :trackable, :validatable
end

tourist_mailer.rb

class TouristMailer<ApplicationMailer
 default from:'<*******:@g mail.com>'

 default_payment_mail(tourist)
     @tourist=tourist
     mail(
         from:'<******@g mail.com>',
         to: '<#{@tourist.email}>',
         subject: 'Contact Us'
         )
 end

end

trust_payment_mail.html.erb

<html lang="ja">
 <head>
   <meta content="text/html; charset=UTF-8"/>
 </head>
 <body>
   <h2><%=@tourist%> Dear </h2>
   <hr of >
   <p>
     Hi <%=@tourist%>!</p>
   <hr of >
 </body>
</html>

ruby-on-rails ruby

2022-09-30 10:27

1 Answers

Error Message

 undefined method `email` for #<TouristsController: xxxxxxxxxxx>

You can see that you have passed the TouristsController itself instead of the Tourist model.

Perhaps TouristsController is defined in controller/tourist/done.controller.rb, so self refers to the TouristsController itself.

I believe that there is a process related to payment somewhere in the Tourist model, so please call the relevant Tourist instance to create an email from where it is linked.

If possible, the folder structure of the project does not meet the Rails standard, so it is recommended that you read it through Ruby on Rails Guide etc.


2022-09-30 10:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.