user3576036 user3576036 -4 years ago 168
Ruby Question

NoMethodError: undefined method `mail' for main:Object on rails console

I am trying to test the working of mailer. Normally on rails I first test my code logic on console level and then once it is successful I put it into the real source code. I am trying to do the same while working on ApplicationMailer. I followed some other solution and first ran the following on rails console to first set up the ActionMailer

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: '',
port: 587,
domain: '',
authentication: 'plain',
enable_starttls_auto: true,
user_name: '***********',
password: '******'

and then I ran my code:

y.include? x
if true
@receiver = Model.where(category_id: "#{x}").pluck(:email)
mail(to: @receiver, subject: @subject)

I'm getting the following error:

NoMethodError: undefined method `mail' for main:Object
from (irb):19

Could somebody please tell me how make this work on rails console?

Answer Source

You can test mail using following way

ActionMailer::Base.mail(from: "", to: @receiver, subject: @subject, body: "Test").deliver
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download