Reputation: 127
I'm working on a Rails app which should send a confirmation email when a new user registers.
My mailer looks like this:
def notify_email(volunteer)
@volunteer= volunteer
@admin = Volunteer.first
mail(to: @admin.email, subject: 'New Application from ' + volunteer.first_name+ '!', body:
'You have new applicants, please go check on your admin dashboard!
You can contact ' + @volunteer.first_name+ ' at: ' [email protected]+ '.')
end
end
In my production.rb file I have email configurations set as follows(gmail username/password replaced with x's):
config.action_mailer.perform_caching = false
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { :host => 'localhost:8080' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => "587",
:domain => "gmail.com",
:user_name => 'xxxxxx',
:password => 'xxxxxxx',
:authentication => "plain",
:enable_starttls_auto => true
}
My controller has this code:
def create
@admin= Volunteer.first
@volunteer = Volunteer.create(volunteer_params)
@volunteer.save
if @volunteer.save
flash[:success] = "Successfully Registered!"
#email notifes admin of new registration
NotifyMailer.notify_email(@volunteer).deliver_now
redirect_to '/volunteer'
end
And finally when I test the app on the local server the console gives me this information(emails x'ed out again):
NotifyMailer#notify_email: processed outbound mail in 1.5ms
Sent mail to [email protected] (2004.5ms)
Date: Sun, 06 Jan 2019 16:04:49 -0600
From: [email protected]
To: [email protected]
Message-ID: <[email protected]>
Subject: New Application from Rachel!
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Can anyone give me insight into what I'm missing? I've checked several forums and threads and it seems like I'm following the right steps.
Thanks in advance.
Upvotes: 0
Views: 205
Reputation: 343
Unable to comment, but what happens if you call
NotifyMailer.notify_email(@volunteer).deliver
instead of
NotifyMailer.notify_email(@volunteer).deliver_now
I believe deliver_now relays on a background worker like sidekiq, plus try the gem "letter_opener" which will open a new tab in your browser to check your emails.
Upvotes: 1