EOF error in Rails utilizing the devise gem - ruby-on-rails

I've recently set up the devise gem for authentication and all is working well excluding the forgot my password function. My smtp is currently pointed towards a yahoo email address. Yet, I get a EOF end of file extension error. In development it delivers message just fine ,but to no avail in production. Also, I initialized the ENV variables for username and password with Heroku Config:set .Addtionally, I tried port 587. Any help would be much appreciated! I'm fairly new to rails and searched for similar log issues, but most varied significantly in similarity to this issue. Thank you!
config.action_mailer.perform_caching = false
config.action_mailer.default_url_options = {:host => 'https:app.herokuapp.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
ActionMailer::Base.smtp_settings = {
:user_name => ENV['example#yahoo.com'],
:password => ENV['examplepass'],
:domain => 'https://example.herokuapp.com/',
:address => 'smtp.mail.yahoo.com',
:port =>465,
:authentication => "plain",
:enable_starttls_auto => true,
}

My first think:
I think your file have non visible characters, try to clean your file. https://alvinalexander.com/blog/post/linux-unix/how-remove-non-printable-ascii-characters-file-unix
Erase the file and create a new one an rewrite the config, avoid the copy paste. maybe works if you do a copy paste without format to note bloc, word something like that and then copy that back to your file.
Also read more What is an EOFError in Ruby file I/O?
https://airbrake.io/blog/ruby-exception-handling/eof-error
Continue searching i found this
EOFError in Devise::PasswordsController#create
Devise mailer EOF error
a user comment this
Ah classic. My config/secrets.yml isn't tracked in git (naturally) and >looks like it was overwritten and lost those entries for the email >provider smtp/username/password at some point. Thanks
Another one Rails EOFError (end of file reached) when saving a devise user

The resolution to my issue was two fold. I didn't have the heroku config vars properly set up and initialized.My .gitignore file didn't have the exclusions as well to prevent uploading to repository. In conclusion, I added the figaro gem, bundle exec install figaro , and it created the application.yml needed to store that actual user/pass information. https://railsapps.github.io/rails-environment-variables.html ----> quite useful in explaining the options for setting the vars.
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com',
:address => 'smtp.sendgrid.net',
:port =>587,
:authentication => :plain,
:enable_starttls_auto => true,
Also in the above code , I didn't have domain specified to heroku.com but my application domain on Heroku. For production.rb you do need the default url set to your applications name. If you kept the default url "heroku.com" in production.rb it would 404 error when the emailed link was clicked on.
config.action_mailer.default_url_options = {:host => 'https://exampleapp.herokuapp.com/' }
Thanks for the help! I also hope this can be of help to other new rails devs.

Related

ruby on rails tutorial ch 10 could get mail but links are wrong also Bitbucket could not add the code

I've partially solved this problem: I could get links with confirmation and resetting password.
The problem is that those links pointing to the wrong app and I need to adjust name of app manually in order to get the right redirection. Heroku representative said that those wrong address related to code....
1.Where in the Michael Harti ruby on rails tutorial could I find and change the code?
I've used Cloud 9 and Bitbucket as repository. I've created the new app on Bitbucket clone my existing app from Bitbucket to Cloud and want to push it to Bitbucket in order to make some changes.
But Bitbucket doesn't allow me to do saying that there is the existing app. clone probably doesn't work in this case.
2.How to create exactly the same app as existing in Bitbucket but with different name on Cloud9 and push it to Bitbucket with different name?
thanks.
//config/environments/production.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
host = 'tatyanaa.herokuapp.com'
config.action_mailer.default_url_options = { host: host }
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com',
:enable_starttls_auto => true
}
If you see that output in console, it means your email was actually sent.
By "sent" I mean that Rails in development mode, instead of really sending the email (so you don't have to setup anything), it outputs it to the console like you can see there.
This configuration can be changed in development.rb by setting
config.action_mailer.delivery_method = :stmp
config.action_mailer.perform_deliveries = true
You are then required to properly configure the smtp settings, check the Action Mailer configuration guide for additional details, should be something like:
config.action_mailer.delivery_method = :stmp
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
address: "foo.bar.com",
user_name: "someone",
password: "apassword"
}
However, I highly suggest you to keep the default configuration and let it log in console instead of sending real emails.
Did you properly write the code in production.rb ?
Here is mine (I've followed the same tutorial as well and it worked):
(production.rb)
....
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
host = 'my_heroku_app_name.herokuapp.com'
config.action_mailer.default_url_options = { host: host }
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com',
:enable_starttls_auto => true
}
....
Also did you properly configure sendgrid as an addon on heroku?
(terminal window)
heroku addons:create sendgrid:starter
If you are stuck and REALLY don't know how to proceed, I recommend you to do the tutorial again from the start. It may seem inefficient to go through the same process again when (I assume) you haven't finished the entire tutorial itself.
Believe me, I've also had the same situation where I "thought" I've followed the every step of the tutorial correctly before the app stopped working for some reason and when I restarted it again from the beginning and followed the steps again, this time with a more relaxed mind, the code worked perfectly :) And I've gone through the same tutorial "4 times" before I could finally "get it". I think it would be good for you if you repeat the same process again as it helps solidify your knowledge AND solve the problem.

Rails Devise Mailer: No Received Messages in Inbox

I'm using Rails 4 and Devise 3. I need to send confirmation e-mails for production. These are the SMTP configs for my config/environments/production.rb
config.action_mailer.default_url_options = { :host => 'smtp.gmail.com' }
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:tls => true,
:port => '587',
:user_name => 'my_email#gmail.com',
:password => 'my_password',
:authentication => 'plain',
:enable_starttls_auto => true
}
Logs say that the e-mail's been sent. However, I don't see anything in the inbox. (yes, mailcatcher is off)
Another question, do the configs of the development file affect the production's environment's in any ways? They shouldn't, correct?
Another important question: Using the way above, how many e-mails can be handled? For an example, if I used a third party say, Mandrill, would be better because up for tens of thousands of e-mails can be handled. What about this way?
P.S I've already tried Mandrill and it worked just fine. I am requested not to use a third party though so I won't be able to use Mandrill.
Lastly, is there any other way of sending the confirmation e-mails from the Rails Devise that I'm unaware of yet? Or are there any other configurations that I need to do OUTSIDE OF RAILS to make this work since I won't be using a third party?
Please make sure you have enter correct host name .
config.action_mailer.default_url_options = { :host => 'your domain name' }
As Rails configuration standard if your application running on local machine it loads development env. file settings, if it is production then it load production env. file settings.
I prefer to use sendgrid or Mandrill by MailChimp, if you ave large application then it is better to use 3rd party addons, for small application you can use Gmail .
hope this will help you :)

How do I enable Devise to send out confirmation emails on Heroku?

I am on heroku so am not clear where and how to set it up so that devise can send out emails.
I actually have two directions to go:
I am using sendgrid, so am wondering how it works with that.
For my hand-rolled mailers, I use PostageApp, which I'd prefer because it allows me to see what's going on with my email. The way I use PostageApp is my Mailers are a class of PostageApp's mailer.
Thanks.
In Rails 3 I used the following settings in config/environments/production.rb
# Disable delivery errors, bad email addresses will be ignored
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => '##YOUR_PROJECTNAME##.heroku.com' }
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => 25,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => ENV['SENDGRID_DOMAIN'],
:authentication => :plain
}
Note: you'll need to substitute in your project name - but all those ENV variables are populated for you automatically by heroku.
I just wanted to let you guys know that with the help of one of our customers, we have been able to add integration instructions for Devise with Postage to our documentation. He has also told us that he is updating the code to work with the newer, modularized version of Devise, and he will give us the code as soon as it is ready.

Sending mail with Rails 3 in development environment

I'm sure this has been asked a million times before but I can't find anything that works for me so I'm asking again!
I just need a way of sending emails using ActionMailer in rails 3. I have followed numerous tutorials including the Railscasts tutorial on the new ActionMailer and I can see the mails being generated but I don't receive them.
I have tried a bunch of different ways but they generally amount to configuring the following settings
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => "587",
:domain => "gmail.com",
:user_name => "xxx#gmail.com",
:password => "yyy",
:authentication => "plain",
:enable_starttls_auto => true
}
I have tried the above code (with valid gmail details of course) in my config/environment.rb, config/environments/development.rb and currently have it in its own initialiser config/initialisers/setup_mail.rb
I have also tried with a few different smtp servers including Gmail and Sendgrid, adjusting the smtp settings accordingly but still nothing. I can see the mail in the terminal and the development log and that's it.
Does anyone know of any other gotcha's that I may have missed that need to be setup for ActionMailer to work? Failing that is there a way of getting more information about why the mails aren't being sent? I have
config.action_mailer.raise_delivery_errors = true
set in my config/development.rb but the development log still just shows the same as I see in the terminal.
For what it's worth, I am developing on a Ubuntu 10.04 laptop just in case there's any specific setup needed for that.
Many thanks
Well I have resolved the issue, but quite why this works and the other methods did not, I don't know.
The solution was to create an initialiser in config/initialisers/setup_mail.rb containing the following
if Rails.env != 'test'
email_settings = YAML::load(File.open("#{Rails.root.to_s}/config/email.yml"))
ActionMailer::Base.smtp_settings = email_settings[Rails.env] unless email_settings[Rails.env].nil?
end
I then added config/email.yml containing the details of the dev and production email accounts
development:
:address: smtp.gmail.com
:port: 587
:authentication: plain
:user_name: xxx
:password: yyy
:enable_starttls_auto: true
production:
:address: smtp.gmail.com
:port: 587
:authentication: plain
:user_name: xxx
:password: yyy
:enable_starttls_auto: true
Like I say, no idea why, but this seemed to do the trick. Thanks all for the pointers
I have the following in config/environments/development.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
The actual mail-configuration, config.actionmailer.* i have placed in config\application.rb.
Hope this helps :)
Try using 'sendmail' instead of 'smtp'.
ActionMailer::Base.delivery_method = :sendmail
ActionMailer::Base.sendmail_settings = {
:address => "smtp.gmail.com",
:port => "587",
:domain => "gmail.com",
:user_name => "xxx#gmail.com",
:password => "yyy",
:authentication => "plain",
:enable_starttls_auto => true
}
Three things.
First, the port is an integer and does not need quotes, as in your first example. (But I think a string should still work.)
Second, don't forget to restart your server each time you modify this (or any) initializer file. This could explain why you didn't see an error after adding:
config.action_mailer.raise_delivery_errors = true
Without having that error message, it's hard to determine why the mail wasn't going but now is. One possiblity is your use of double quotes around the password. If you were using a strong password and had a token in your password that wasn't escaped it could have been reinterpreted. (i.e. "P#ssw\0rd" would become P#ssrd). For just this reason, I always use single quotes in my code unless I specifically need the syntactic sugar.
Lastly, enable_starttls_auto: true is the default and unnecessary.
ActionMailer::Base.delivery_method = :sendmail
and
config.action_mailer.perform_deliveries = true
were the two necessary steps that got me over this issue
Just put all config to:
config/environments/development.rb
I mean
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => "587",
:domain => "gmail.com",
:user_name => "xxx#gmail.com",
:password => "yyy",
:authentication => "plain",
:enable_starttls_auto => true
}
and
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
It worked for me.
In addition to, your gmail username does not alias.
Ref: https://support.google.com/mail/answer/12096?hl=en
My two pennies worth:
I had those exact same symptoms with Rails 5.1: Nothing happened, the settings in my development.rb file were utterly ignored...
Then I remembered to restart the machine! (which solved magically the issue)
This had been pointed out by a couple of previous comments.
The issue is tricky however because you do not expect this behavior. In my view, the default comments in development.rb are, in this respect, misleading:
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since *you don't have to restart the web server when you make code changes*.

Has anyone successfully set up their email settings on EngineYard?

I am attempting to add email capabilities to my app (forgotten password, notifications, etc.) and I am using EngineYard for hosting. I have successfully configured email in my test environment but upon uploading to EY it seems to error out in Production. I don't pay for their support and the only resource is a bit vague (or beyond me).
I am curious to know if there is any specific file additions, server set up etc. that is needed when using email on EY. I am using Google apps so I thought it would be as easy as adding the same code block for test in production but doesn't seem to be the case.
Here's my config for Google apps, in .../config/environments/production.rb:
require 'tlsmail'
Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:tls => true,
:domain => 'example.com',
:authentication => :plain,
:user_name => "sender#example.com",
:password => 'tr1ckypwd!'
}
Note, for the security minded out there, I actually keep the password in a separate file and have code to patch it into the settings on launch, but I figured that would distract from the meat of the response.
Hope that helps.

Resources