ActionMailer not sending mail in development Rails 5 - ruby-on-rails

I am having some problem with sending email in my web-application. When I am running development the email is not sent even though it is showing as sent in the Console.
This is my settings in config/environments/development.rb
# Email
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: '587',
enable_starttls_auto: true,
user_name: ENV["gmail_username"],
password: ENV["gmail_password"],
authentication: :plain,
domain: 'gmail.com'
}
In my controller I am sending mail using this call:
JobMailer.send_accept_job_mail(#app_user, #job.id).deliver
The mail is showing as "sent" in the Console, but it is not sent to the specified mail.

You need to use deliver! to send out the mail immediately.
Just update the code to
JobMailer.send_accept_job_mail(#app_user, #job.id).deliver!
-- edited to use deliver! method, per comments.

Related

ActionMailer not sending mail in development using Spree

I'm using Spree to develop an E-commerce. I was using part this tutorial to send emails using ActionMailer, but I can't make it work.
My controller
UserMailer.sign_up_confirmation(spree_current_user).deliver
My develpment.rb
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
user_name: ENV['gmail_username'],
password: ENV['gmail_password'],
authentication: 'plain',
enable_starttls_auto: true
}
There is no error in the console and the mail it seems to be delivered right, but there is no email on my gmail account. I used this code in a previous project and worked fine. So, is Spree doing something to my email delivering?

Mail sending issue using dreamhost with ruby on rails

I'm trying to send mail using using dreamhost credential with ruby on rails.
My development.rb file mail setting as following.
config.action_mailer.smtp_settings = {
address: "dreamhost.com",
port: 587,
domain: "www.dreamhost.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV['mailer'],
password: ENV['mailer_password']
}
Mail is not able to send using above mail configuration I'm getting error like Errno::ECONNREFUSED (Connection refused for "dreamhost.com" port 587).
Can any one help me for this issue?
This is my profile I use on Dreamhost
config.action_mailer.perform_caching = false
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
config.action_mailer.raise_delivery_errors = false
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_options = {from: 'notifications#mywebsite.org'}
config.action_mailer.smtp_settings = {
address: 'sub5.mail.dreamhost.com',
port: 587,
domain: 'mywebsite.org',
user_name: 'notifications#mywebsite.org',
password: 'mypassword',
authentication: :login,
enable_starttls_auto: false }
Note that sub5.mail.dreamhost.com is domain-dependent address of your datacenter server.
NB: Password should be hidden into ENV variables or other external file outside version control

Ruby on Rails: How to Configure the Devise Mailer?

I have made an application on Ruby on Rails. I'm using Devise and I need to use the recoverable password feature.
I found these configurations on development.rb:
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 2525,
domain: "gmail.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: "MY_EMAIL",
password: "MY_PASS"
}
When I test it, it looks okay, It doesn't throw any exception on the application, but the email never comes. Please, how can I configure this?
For using locally, I recommend using something like letter_opener.
For deploying the app I'd recommend using a service like Sendgrid, it has a free tier that is good enough for small apps.
If you insist on using GMail for e-mails, try using TLS:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
domain: "gmail.com",
port: 587,
user_name: "jorge#example.org",
password: "your_password",
authentication: 'plain',
enable_starttls_auto: true
}
Stumbled across this older question and figured I would provide a current answer here. If you're trying to use a Gmail account with your Devise Rails app for any reason (prototyping, developing, etc - no judgements), Pedro's answer is spot on with 1 exception. The password for the SMTP server is not your user password. This may have been ok in the past, but now you have to generate a new app password separate from your user password.
Directions can be found on Google's Support site here: https://support.google.com/accounts/answer/185833?hl=en

Rails SendGrid Email From Development Environment

We use SendGrid in a production app and it works fine. We were recently trying to test a new feature/email in development however and cannot seem to get an email to send. Any idea where we're going wrong? We are using similar features to production and we also followed SendGrid's implementation guide. Feels like I'm missing something simple!
First I exported the SENDGRID_USERNAME and SENDGRID_PASSWORD and for kicks added it to my .bash_profile
export SENDGRID_USERNAME=xxxxxxx
export SENDGRID_PASSWORD=xxxxxxx
I've confirmed in the console that these exist and are correct.
Created a developer_email.html.erb file:
<p>Hi! Sendgrid test</p>
And a DeveloperMailer file:
class DeveloperMailer < ActionMailer::Base
default from: "tom#xxxxxx.com"
def developer_email(developer_id)
#recipients = ["tom#xxxxxx.com"]
mail(to: #recipients, subject: 'Does sendgrid work?')
end
end
Updated the development.rb file:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.sendgrid.net',
port: '587',
domain: 'localhost:3000',
user_name: ENV['SENDGRID_USERNAME'],
password: ENV['SENDGRID_PASSWORD'],
authentication: :plain,
enable_starttls_auto: true }
When I go to send the email in the console, it acts like it sent, but the email never actually arrives:
DeveloperMailer.developer_email(1) #to send the email. Seems to work:
2.3.1 :001 > DeveloperMailer.developer_email(1)
Rendered developer_mailer/developer_email.html.erb (1.5ms)
DeveloperMailer#developer_email: processed outbound mail in 133.3ms
=> #<Mail::Message:70263824429080, Multipart: false, Headers: <From: tom#xxxxx.com>, <To: ["tom#xxxx.com"]>, <Subject: Does SendGrid Work?>, <Mime-Version: 1.0>, <Content-Type: text/html>>
#But I never get anything sent to my email
Any idea what I might be missing?
EDIT
Updated development.rb file:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.sendgrid.net',
domain: 'example.com',
user_name: ENV['SENDGRID_USERNAME'],
password: ENV['SENDGRID_PASSWORD'],
authentication: :plain,
enable_starttls_auto: true }
Still no email though.
First, do telnet by following commands
telnet smtp.sendgrid.net 2525
If you get proper response from SMTP Service then change SMTP port from 587 to 2525
In my case "587 port" is not responding
After changing the port it works for me
domain in this context is an SMTP HELO domain, not the actual environment's domain. Change it to the same domain you use in your SendGrid profile and don't specify a port and give it a try.
You'd need to verify the sender email or domain of the sender email before you can send an email with SendGrid. See https://sendgrid.com/docs/ui/sending-email/sender-verification/ and https://sendgrid.com/docs/for-developers/sending-email/sender-identity/#domain-authentication

How to send emails in development environment using gmail SMTP and devise?

I am trying to send emails while being on localhost and using devise (I need emails for user registration and password reset)
I have put this in my environment.rb file
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "gmail.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["username"],
password: ENV["password"]
}
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
but I am not getting any mails and not seeing any error too (devise says ).
What am I missing ?
Where can I see the log for emails (success or
failure) ?
EDIT - OK, it worked after adding this line
:openssl_verify_mode => 'none'
Check this too rails email error - 530-5.5.1 Authentication Required.

Resources