Action Mailer Not delivering Emails - MailCatcher and sendmail - ruby-on-rails

I am using Rails 5. I have the following configurations in my config/environments/development.rb and config/environments/staging.rb.
config/environments/development.rb
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { address: "localhost", port: 1025 }
When I call the method that sends email, I get the following output.
Rendering mailer/consolidated_s3_storage_report.html.erb
Rendered mailer/consolidated_s3_storage_report.html.erb (0.4ms)
Mailer#consolidated_s3_storage_report: processed outbound mail in 17668.1ms
=> #<Mail::Message:86763960, Multipart: true, Headers: <From: mcds#sheridan.com>, <To: mcds.support#sheridan.com>, <Subject: 2017 July - S3 Storage Report>, <Mime-Version: 1.0>, <Content-Type: multipart/mixed; boundary="--==_mimepart_595c962cc36fb_1be1b2198436941"; charset=UTF-8>>
But email is not delivered to my gmail. The 'from' address is 'default from' from which all other emails are sent. Please clarify why my emails are not delivered.

You seem to be using Mailcatcher. Mailcatcher doesn't deliver messages, its to prevent messages from delivering to the actual To email addresses but lets you check of the message is framed correctly. Developers use Mailcatcher in development enviroments to see if the emails are rendered as they expect them to look like without spamming the To email holder.
All the emails that are sent to Mailcatcher can be viewed in a web interface. Visit http://localhost:1080 on your computer, you should be able to see all the emails you send so far from the development environment.

Following is the configuration for send mail to gmail:
config/environments/development.rb
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "user#gmail.com", #your gmail id
:password => "password", #your gmail password
:authentication => "plain",
:enable_starttls_auto => true
}

Related

Not receiving mail from Heroku Sendgrid addon

So i've look at a few similar posts here on SO, but for some reason my sendgrid config in heroku is not working.
Here's my config / production.rb
config.action_mailer.default_url_options = { :host => 'poliking.herokuapp.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
ActionMailer::Base.smtp_settings = {
:from => 'wesleycreations#gmail.com',
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'poliking.herokuapp.com',
:address => 'smtp.sendgrid.net',
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}
Everything worked perfectly fine in development. I tried all the obvious, YES variables are properly set and YES I enabled my gmail to allow mail from less secure apps.
added gem sendgrid gem to my gem file
gemfile.rb
gem 'sendgrid-ruby'
Again, everything working fine in development and I am receiving email to same email address. But this isn't working in production. Any thoughts?
Here's the log:
...MailForm::Notifier#contact: processed outbound mail in 3.3ms...
Delivered mail 5f246d3cbf2d9_42af68b690f1c810d6#dad81cb4-1ce9-440e-b8...
With config.action_mailer.raise_delivery_errors = false, the errors raised during e-mail delivery will be suppressed.
Therefore, change that option to true so that you can diagnose the problem.

Why can't I see any emails in my inbox sent from my Heroku Rails app using SendGrid SMTP Relay in development mode?

I'm trying to switch over to SendGrid from Mandrill in my Rails 4.2 app through SendGrid's SMTP Relay. I have set the 'To Email' to be my personal email address so that I can view the emails that have been sent, however none of the emails actually appear in my inbox despite the rails console claiming to have processed and sent the email.
I am fairly certain all my mailers have the appropriate smtp settings as I have mostly followed the instructions provided on the SendGrid website: https://sendgrid.com/docs/Integrate/Frameworks/rubyonrails.html
I have also tested my connectivity to SendGrid's SMTP Relay through telnet and the connection is succesful.
My SendGrid dashboard indicated that 0 emails have been sent. None of my emails appear under the Suppressions tab either so it's not like they have bounced or have been blocked.
This is in my config/environment.rb:
ActionMailer::Base.smtp_settings = {
:user_name => 'apikey',
:password => ENV['SENDGRID_API_KEY'],
:domain => 'heroku.com',
:address => 'smtp.sendgrid.net',
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}
This is in my config/environments/development.rb:
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { :host => 'smtp.sendgrid.net' }
This is the line in my controller that calls my ApplicationMailer:
ApplicationMailer.send_email(user, 'mypersonalemail#email.com', 'Test Subject').deliver
And this is what gets printed in the console when the mailer method is executed:
ApplicationMailer#send_email: processed outbound mail in 789.9ms
Sent mail to mypersonalemail#email.com (103.4ms)
But I still don't get any emails in my inbox or spam folder. Does anyone know how I can solve this? Thanks in advance.
Your domain and host options are wrong. Use localhost:3000 (unless you're using docker or something at which point replace localhost:3000 with 0.0.0.0:8000)
#/environments/development.rb
#Mailer Options
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'localhost:3000',
:enable_starttls_auto => true
}
config.action_mailer.default_url_options = { host: 'http://localhost:3000' }
config.action_mailer.asset_host = 'http://localhost:3000'
Make sure to add the sendgrid credentials to your local machine as environment vars. To get them, go to your heroku app and click on settings, then "reveal config vars". Then add those sendgrid credentials to your local machine as env. vars and you're done.

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

Mandrill send email ruby on rails

Im using mandrill for sending email and it show for some emails that the email From: ma#mail133-28.atl131.mandrillapp.com [mailto:ma#mail133-28.atl131.mandrillapp.com] On Behalf Of info#****.com
in my name mailer default from: "info#****.com"
and in the development.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :letter_opener
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.mandrillapp.com",
:port => 587,
:domain => 'www.****.com',
:user_name => '**#**.ca',
:password => '***',
:authentication => :plain,
:enable_starttls_auto => true
}
Why is that? i want to show from: info#****.com without this ma#mail133-28.atl131.mandrillapp.com [mailto:ma#mail133-28.atl131.mandrillapp.com] On Behalf Of info#****.com
From Mandrill KB
If your recipients use Outlook, Hotmail (and other Microsoft webmail
services), or Gmail, they may see an indication in the email that it
was sent by Mandrill on your behalf instead of just your 'from' name
and address. Add SPF and DKIM records to your sending domains to
remove the 'on behalf of' or 'via' information.
Instructions on how do that can be found here: https://mandrill.zendesk.com/hc/en-us/articles/205582277-How-do-I-add-DNS-records-for-my-sending-domains-

sendmail with RoR: not receiving mails

I am using sendmail in my Rails app. The configrations are as given below,
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'localhost' }
config.action_mailer.default_options = {from: 'no-reply#example.com'}
config.action_mailer.delivery_method = :sendmail
When I restart my apache2 server and sendmail service, I will get a mail(one time). However, if, later, I try to send the mail, it shows the status as 200-ok, but I won't receive any mail.
FYI:
Same issue is found even for localhost:3000
Also below is my mail.log output
Nov 25 17:58:02 dosysnet267 sendmail[1602]: sAPCS2X3001602: Authentication-Warning: dosysnet267.dreamorbit.in: DREAMORBIT\\karthik.ds set sender to no-reply#gmail.com using -f
Nov 25 17:58:02 dosysnet267 sendmail[1602]: sAPCS2X3001602: from=no-reply#gmail.com, size=473, class=0, nrcpts=1, msgid=<547475d2aa8c3_5dc181896c66978#dosysnet267.mail>, relay=DREAMORBIT\\karthik.ds#localhost
Nov 25 17:58:03 dosysnet267 sm-mta[1604]: sAPCS2bg001604: from=<no-reply#gmail.com>, size=774, class=0, nrcpts=1, msgid=<547475d2aa8c3_5dc181896c66978#dosysnet267.mail>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Nov 25 17:58:03 dosysnet267 sendmail[1602]: sAPCS2X3001602: to=karthik.ds#example.com, ctladdr=no-reply#gmail.com (1200096887/1200095745), delay=00:00:01, xdelay=00:00:01, mailer=relay, pri=30473, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (sAPCS2bg001604 Message accepted for delivery)
Nov 25 17:58:05 dosysnet267 sm-mta[1609]: sAPCS2bg001604: to=<karthik.ds#example.com>, delay=00:00:03, xdelay=00:00:02, mailer=esmtp, pri=120774, relay=example.com. [174.136.95.75], dsn=2.0.0, stat=Sent (OK)
Any idea?
When i need to send a email when testing an rails app do i all ways use this code inside the development file. Then just fill it out with your gmail credentials. The rails app will then send the email through gmail with your gmail account.
config/environments/development.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'gmail.com',
:user_name => 'youremail#gmail.com',
:password => 'yourpassword',
:authentication => 'plain',
:enable_starttls_auto => true }
config.action_mailer.default_url_options = { :host => "localhost:3000" }
Thanks for looking into the issue. It is working fine. I couldn't receive mails, due to my mailbox issues.

Resources