sendmail with RoR: not receiving mails - ruby-on-rails

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.

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.

Emails send from rails with O365 being rejected as spam

I have a Rails 5 app deployed on Heroku. I'm using devise for email and have setup everything correctly to send password reset emails. This works perfectly in my dev environment. However, when I send from production I get an error in my 0365 inbox that says:
Generating server: CO2PR13MB0140.namprd13.prod.outlook.com
myemail#gmail.com
Remote Server returned '550 5.7.708 Service unavailable. Access denied, traffic
not accepted from this IP. For more information please go to
http://go.microsoft.com/fwlink/?LinkId=526653 AS(8561)
[CO2PR13MB0124.namprd13.prod.outlook.com]'
Original message headers:
Received: from CO2PR13MB0140.namprd13.prod.outlook.com
([fe80::c872:9c6:9d6a:8b3]) by CO2PR13MB0140.namprd13.prod.outlook.com
([fe80::c872:9c6:9d6a:8b3%4]) with mapi id 15.20.1339.019; Wed, 14 Nov 2018
02:42:20 +0000
MIME-Version: 1.0
Content-Type: text/plain
Date: Wed, 14 Nov 2018 02:42:20 +0000
Message-ID:
<5beb8b87e888a_42b06292aba70609bd#01184e4c-2116-478b-a773-fcc26ac206aa.mail>
Subject: Reset password instructions
In looking into this, and talking to support, it appears that the it's being rejected because a third party server is (my app on Heroku I'm assuming) is trying to send out the email with 0365 settings.
Here are my development.rb settings that work perfectly:
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_caching = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.office365.com',
:port => '587',
:authentication => :login,
:user_name => ENV['365_USERNAME'],
:password => ENV['365_PASSWORD'],
:domain => 'mysite.com',
:enable_starttls_auto => true
}
Here are my production.rb settings that cause O365 to reject the email. I've tried playing with these quite a bit. And I've ensured that the "from" email matches the login email. i.e. I'm not trying to send from no-reply#mysite.com or similar.
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_caching = false
config.action_mailer.default_url_options = { :host => 'www.mysite.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.office365.com',
:port => '587',
:authentication => :login,
:user_name => ENV['365_USERNAME'],
:password => ENV['365_PASSWORD'],
:domain => 'mysite.com',
:enable_starttls_auto => true
}
From discussions with support. I may need to add an SPF TXT record to allow emails to be sent from a remote server. The problem is, I have no idea what to add to the SPF record. My current spf record is:
v=spf1 include:spf.protection.outlook.com -all
Their response just says they have blacklisted your IP, so it’s not down to your message content.
If you are sending from Heroku, you may need to list them in your SPF as well. Also ensure that your host name resolves backwards as well as forwards - that should be possible in Heroku’s control panel.
Once you’ve done that, check your SPF record gives a pass to your message source using kitterman.com or mxtoolbox testing services.
O365’s spam filter and blocking policy is pretty bad anyway, however I have had success in asking their support to remove blocks, though you need to persevere because they reject all such requests by default. This is poor service, but it’s still far better than you will get from gmail.

Rails w/devise authentication what is the configuration of iRedMail?

We're using successfully iRedMail in 4 email servers (8 domains) for our own email accounts.
We develop web apps based on RoR. We would like to know what is the iRedMail configuration for sending to users, via rails and devise gem, https://github.com/plataformatec/devise, the password reminds, emails confirmations, etc.. What is the difference between address and domain? How to test?
After Googling and posting in iRedMail forum unsuccessful, we only find smt gmail config, please find below.
Thanks in advance!
==== DEVISE config/environments/development.rb ====
SMTP GMAIL CONFIG:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "mail.google.com",
:user_name => "my#gmail.com",
:password => "mypassword",
:authentication => :plain,
:enable_starttls_auto => true
}
==== BACK-END ====
iRedMail 0.9.7 MARIADB edition.
Debian GNU/Linux 9 (stretch) in a fresh OVZ-6GB
Mysql/MariaDB w/adminer
Apache/2.4.25 (Debian)
PHP 7.0.19-1
Ruby 2.5.0, Rails 5.1.5 and Phusion Passenger 5.2.1
No errors: /var/log/iredapd/iredapd.log
=============================
Editing DEVISE config/environments/development.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.smtp_settings = {
:address => "mx.coopeu.com",
:port => 587,
:domain => "mx.cooopeu.com",
:user_name => "coopeu#coopeu.com",
:password => "password",
:authentication => :plain,
:enable_starttls_auto => true
}
Also raising error:
Net::SMTPFatalError in ConfirmationsController#create
554 5.7.1 : Recipient address rejected: Sender is not same as SMTP authenticate username
It means you use user "coopeu#coopeu.com" for SMTP authentication, but specify user "someone-else#somedomain.com" as the sender address.
If you need to allow the sender address mismatch for this smtp user, you can add one setting in
/opt/iredapd/settings.py
to allow it, like below:
ALLOWED_LOGIN_MISMATCH_SENDERS = ['coopeu#coopeu.com']
Restarting iredapd after modified "settings.py".
and it's working right

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.

Action Mailer Not delivering Emails - MailCatcher and sendmail

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
}

Resources