Notification emails not working on Redmine using SMTP and Gmail - ruby

I have Redmine 2.2.1 installed and running, but I can't get the notification emails to work. I keep getting the following error:
An error occurred while sending mail (getaddrinfo: Name or service not known)
I can't figure out what it is I'm missing. I followed these instructions to set up email notifications using Gmail, but it seems like no matter what changes I make to my configuration.yml file I still get the same error.
This is what my configuration.xml file looks like:
production:
email_delivery:
delivery_method: :smtp
smtp_settings:
tls: true
enable_starttls_auto: true
address: "smtp.gmail.com"
port: 587
domain: "smtp.gmail.com"
authentication: :plain
user_name: "email#mydomain.com"
password: "mypassword"
Everything else is commented out.
I tried changing and removing both the tls and enable_starttls_auto options but changes to the configuration.yml file do not affect the error message.
I also checked for the common mistakes that I found on other forums, like tabs in the configuration file or the production: config being defined twice, etc.
I enabled SMTP on my Gmail account.
I also tried setting up ActionMailer, but I'm not sure what I'm supposed to do with it or if I even need to do that. There was no mention of that being required anywhere. I have it installed and set up but not sure if that's doing anything.
Redmine 2.2.1
ruby 1.8.7 (2012-02-08 patchlevel 358) [x86_64-linux]
Rails 3.2.11
gem version 1.8.24
Amazon AMI Linux
production.log:
Started GET "/redmine/admin/test_email" for 98.xxx.xx.xx at Wed Jan 16 12:28:23 -0800 2013
Processing by AdminController#test_email as HTML
Current user: oscarm (id=3)
Rendered mailer/test_email.text.erb within layouts/mailer (0.1ms)
Redirected to http://mydomain/redmine/settings /edit?tab=notifications
Completed 302 Found in 35ms (ActiveRecord: 0.7ms)
Started GET "/redmine/settings/edit?tab=notifications" for 98.xxx.xx.xx at Wed Jan 16 12:28:23 -0800 2013
Processing by SettingsController#edit as HTML
Parameters: {"tab"=>"notifications"}
Current user: oscarm (id=3)
Rendered settings/_general.html.erb (6.8ms)
Rendered settings/_display.html.erb (9.0ms)
Rendered settings/_authentication.html.erb (5.9ms)
Rendered settings/_projects.html.erb (5.9ms)
Rendered queries/_columns.html.erb (6.5ms)
Rendered settings/_issues.html.erb (12.6ms)
Rendered settings/_notifications.html.erb (6.4ms)
Rendered settings/_mail_handler.html.erb (1.9ms)
Rendered settings/_repositories.html.erb (10.3ms)
Rendered common/_tabs.html.erb (66.2ms)
Rendered settings/edit.html.erb within layouts/admin (67.0ms)
Rendered admin/_menu.html.erb (5.6ms)
Rendered layouts/base.html.erb (19.3ms)
Completed 200 OK in 222ms (Views: 91.3ms | ActiveRecord: 4.3ms)

So I figured out what my issues were...
I kept making modifications to the configuration.yml file and expecting redmine to read it every time I reloaded the page but that wasn't the case. Redmine only reads the configuration files on startup so I had to restart redmine every time I made a change to the config file.
One of the things I tried was installing the action_mailer_optional_tls plugin in redmine/plugin but I finaly found out that this plugin only works for ruby 1.8.6 and I'm using ruby 1.8.7 which has this functionality built-in. After removing the action_mailer_optional_tls directory from redmine/plugin and restarting redmine I was able to send notification emails :-)
So here's my final configuration to make redmine work with gmail:
production:
email_delivery:
delivery_method: :smtp
smtp_settings:
address: "smtp.gmail.com"
port: 587
domain: "smtp.gmail.com"
authentication: :plain
user_name: "myemail#mydomain.com"
password: "mypassword"
enable_starttls_auto: true
Hope this helps someone out there having the same issue.

Related

ruby rest-client ipv6 request failure with Apache 2.2.31

I've been stuck with this for about two days...
I use ruby(version 2.3.3p222) gem rest-client(v2.0.0) to send a GET request with a ipv6 url to the server (Apache/2.2.31):
url = 'https://[fd36:4928:8040:dc10:0000:0000:0000:0160]:8080/resources/1'
resource = RestClient::Resource.new(url, :ssl_version => 'TLSv1', :verify_ssl => false, :headers => {'Authorization' => 'Basic cm9vdDAbCdEfwYXNzMSE='})
resource.get
I got a 400 bad response and the body says:"Your browser sent a request that this server could not understand. Additionally, a 400 Bad Request error was encountered while trying to use an ErrorDocument to handle the request"
However I can use curl command with the same parameters and get the right response, so I suspect maybe it's something wrong with the header of my rest-client request.
PS: I also tested with adding the 'host'
header: {'Authorization' => 'Basic cm9vdDAbCdEfwYXNzMSE=', 'host' => '[fd36:4928:8040:dc10:0000:0000:0000:0160]:8080' }
It still failed with the same bad response.
I just noticed the appache error for this request, it says:
"httpd[29124]: [error] Hostname fd36:4928:8040:dc10:0000:0000:0000:0160 provided via SNI and hostname fd36:4928:8040:dc10:0000:0000:0000 provided via HTTP are different
"
The curl command you supplied would translate --user admin:password into the following header:
Authorization: Basic YWRtaW46cGFzc3dvcmQ=
However, you're sending
Basic: cm9vdDAbCdEfwYXNzMSE=
which is not the same thing... so the server is probably complaining about not getting the correct auth...
After debugging and googling for another day, this problem seems to be clear:
From a similar bug report to chrome https://bugs.chromium.org/p/chromium/issues/detail?id=500981, "SNI is only hostnames, and should never contain IPs.". However ruby does use ip as hostname (in this case rest-client is nothing to blame since it just delegate everything down to ruby lib). You can find evidence in Net::HTTP#connect (around line 922):
# Server Name Indication (SNI) RFC 3546
s.hostname = #address if s.respond_to? :hostname=
Just comment out the last line it will work (to workaround this you have to do a monkey patch). Additionally, as pointed out by #alberge, host header does not contain brackets, the final request host header is like this: "FD36:4928:8040:DC10::162", no "[ ]" around.
Also on Apache side, it does something wrong since it just strips off everything from the last colon to get the host name without any extra check- this still exists in version 2.4.10, not sure if it is fixed or not.
This appears to be either a bug in rest-client or a regression in Ruby Net::HTTP.
https://github.com/rest-client/rest-client/issues/583
What version of Ruby are you using? Have you tried using Ruby 2.1 to see if it works there?
EDIT:
This is Ruby Bug #12642. The Host header for an IPv6 address is sent with no enclosing [ ].
Ruby in 2.1.6 - 2.1.10 doesn't have the bug, but versions >= 2.2.0 are affected.
And worse still, there's a bug with setting an explicit IPv6 Host header so you get an exception URI::InvalidComponentError: bad component(expected host component): [

Github pages Jekyll static blog outdated

I setup a Jekyll blog on Github-Pages 5 months ago. It was working at that time, and I though it would be a nice place to post things.
Long story short, I wrote a first post, but then I never used, until yesterday when I wanted to check that all was working fine, but it was not. I also could not run Jekyll locally.
I do not use ruby on my daily basis ,so they were outdated. I though maybe if I update it and generate the site again everything is going to be working fine.
I updated ruby from 2.1.2 to 2.2.1, and I tried other things to make it work. Now is working locally, but throwing this
Generating...
Defaults: An invalid front-matter default set was found:
[{"scope"=>{"path"=>"_posts/"}, "values"=>{"author"=>"Agustin Gambina"}}]
Defaults: An invalid front-matter default set was found:
[{"scope"=>{"path"=>"_posts/"}, "values"=>{"author"=>"Agustin Gambina"}}]
I also added a Gemfile to the root directory
source 'https://rubygems.org'
require 'json'
require 'open-uri'
versions = JSON.parse(open('https://pages.github.com/versions.json').read)
gem 'github-pages', versions['github-pages']
When I run
github-pages health-check
I get this
Checking domain littlebit.me...
Uh oh. Looks like something's fishy: Domain does not resolve to the GitHub Pages server
Does anyone know why it happened to me that is not working anymore? was because it was outdated and something changed?
thank you
You have an error in your _config.yml file :
-
-
scope:
path: "_posts/scala"
values:
author: Agustin Gambina
Must be :
-
scope:
path: "_posts/scala"
values:
author: Agustin Gambina
This is not a fatal error, so your site build, but your rule is not applied.
Concerning the health-check, it works for me as it checks littlebit.me that resolve to github IPs.
$: dig littlebit.me
...
littlebit.me. 1800 IN A 192.30.252.154
littlebit.me. 1800 IN A 192.30.252.153
If it doesn't work on your PC, you may have a DNS problem. Maybe you've set a bad value in your hosts file ?

Ruby Sinatra/Postgres - can't connect to heroku database with PG.connect?

I am trying to get a site set up on Heroku using Sinatra and PostgreSQL. It worked locally (connecting to local database), but after pushing it to Heroku and changing my PG.connect to reflect that, I get an Internal Server Error the moment a page tries to access the database.
require 'uri'
require 'pg'
uri = URI.parse(ENV['DATABASE_URL'])
def db(uri)
begin
connection = PG.connect(uri.hostname, uri.port, nil, nil, uri.path[1..-1], uri.user, uri.password)
yield(connection)
ensure
connection.close
end
end
I am pretty sure these are parsing correctly, because ENV['DATABASE_URL'] displays the full postgres://user:password#host:port/database information that I'm expecting, and if I do the same in IRB uri.hostname, ui.port, etc all return what's expected .
This is my first time trying to get a site working on Heroku, so I am not even sure how to troubleshoot this. (And I googled for about all of yesterday.)
Results for heroku pg:
=== DATABASE_URL
Plan: Hobby-dev
Status: Available
Connections: 0/20
PG Version: 9.4.2
Created: 2015-05-30 19:24 UTC
Data Size: 17.7 MB
Tables: 5
Rows: 9320/10000 (In compliance, close to row limit)
Fork/Follow: Unsupported
Rollback: Unsupported
And all the tables show up when when I do heroku pg:psql <database> from the cli.
Some answers I've seen said to add database.yml to my root app directory, so:
production:
adapter: 'postgresql'
database: '<database>'
host: ENV['DATABASE_URL']
username: '<username>'
There's probably something simple I'm missing, but I haven't seen a complete guide for Sinatra/PSQL on Heroku - nothing that goes specifically into setting up and connecting to your database. (Everything seems Rails-related.)
In your database.yml file you need to specify the correct host for the host entry. You are passing what is stored in DATABASE_URL (something like postgres://user:password#host:port/database) but it should just be the host.
You will also need to specify a port if it isn't the default for PostgreSQL.
Edit: should also point out if you plan to store the host (or anything else - you definitely should for username and password) in an environment variable you'll need to wrap it, e.g. <%= ENV['HOST'] %>, not just ENV['HOST'] (i.e. how you have in the database.yml excerpt above)

Credentials issues using the rt-client rubygem (rest interface to request tracker ticket system)

I am having issues using the rt-client gem(link), as it keeps returning a "RT/4.0.8 401 Credentials Required". The REST interface for this site is working, as I have some perl scripts that are currently working with it in a similar fashion.
test.rb
#!/usr/bin/env ruby
require 'rt/client'
rt = RT_Client.new
id = rt.create( :Queue => "General",
:Subject => "Test",
:Requestor => "test#example.org",
:Text => "Ignore me"
)
.rtclientrc
server=http://example.org/
user=exampleuser
pass=examplepass
cookies=tmp
Versions
Gem Version: rt-client-0.5.0
RT Version: 4.0.8
Ruby Version: 1.9.3p327
Output
Payload for new ticket:
------xYzZY492386xYzZY
Content-Disposition: form-data; name="content";
Queue: General
Subject: Test
Requestor: test#example.org
Text: Ignore me
id: ticket/new
------xYzZY492386xYzZY--
"RT/4.0.8 401 Credentials required\n"
I am seeing the error when I do a "puts id.inspect" at the bottom of test.rb, as the ticket is not getting created.
Is this perhaps an issue with the handling of cookies? I was trying to avoid writing a custom solution in Net::HTTP if possible, but I will go that route if this continues to be a hassle.
Author of the rt-client ruby gem here.
This was resolved some time ago and I know this is old, but it is ranked highly in a Google search for the gem. If anyone finding this question still has issues with rt-client, the gem is now on github.com. If you wish, please clone it, make your fix and send me a pull request.
https://github.com/uidzip/rt-client

Job handler serialization incorrect when running delayed_job in production with Thin or Unicorn

I recently brought delayed_job into my Rails 3.1.3 app. In development
everything is fine. I even staged my DJ release on the same VPS as my
production app using the same production application server (Thin),
and everything was fine. Once I released to production, however, all
hell broke loose: none of the jobs were entered into the jobs table
correctly, and I started seeing the following in the logs for all
processed jobs:
2012-02-18T14:41:51-0600: [Worker(delayed_job host:hope pid:12965)]
NilClass# completed after 0.0151
2012-02-18T14:41:51-0600: [Worker(delayed_job host:hope pid:12965)] 1
jobs processed at 15.9666 j/s, 0 failed ...
NilClass and no method name? Certainly not correct. So I looked at the
serialized handler on the job in the DB and saw:
"--- !ruby/object:Delayed::PerformableMethod\nattributes:\n id: 13\n
event_id: 26\n name: memememe\n api_key: !!null \n"
No indication of a class or method name. And when I load the YAML into
an object and call #object on the resulting PerformableMethod I get
nil. For kicks I then fired up the console on the broken production
app and delayed the same job. This time the handler looked like:
"--- !ruby/object:Delayed::PerformableMethod\nobject: !ruby/
ActiveRecord:Domain\n attributes:\n id: 13\n event_id: 26\n
name: memememe\n api_key: !!null \nmethod_name: :create_a\nargs: []
\n"
And sure enough, that job runs fine. Puzzled, I then recalled reading
something about DJ not playing nice with Thin. So, I tried Unicorn and
was sad to see the same result. Hours of research later and I think
this has something to do with how the app server is loading the YAML
libraries Psych and Syck and DJ's interaction with them. I cannot,
however, pin down exactly what is wrong.
Note that I'm running delayed_job 3.0.1 official, but have tried upgrading to
the master branch and have even tried downgrading to 2.1.4.
Here are some notable differences between my stage and production
setups:
In stage I run 1 Thin server on a TCP port -- no web proxy in front
In production I run 2+ Thin servers and proxy to them with Nginx.
They talk over a UNIX socket
When I tried unicorn it was 1 app server proxied to by Nginx over a
UNIX socket
Could the web proxying/Nginx have something to do with it? Please, any insight is greatly appreciated. I've spent a lot of time
integrating delayed_job and would hate to have to shelve the work or, worse,
toss it. Thanks for reading.
I fixed this by not using #delay. Instead I replaced all of my "model.delay.method" code with custom jobs. Doing so works like a charm, and is ultimately more flexible. This fix works fine with Thin. I haven't tested with Unicorn.
I'm running into a similar problem with rails 3.0.10 and dj 2.1.4, it's most certainly a different yaml library being loaded when running from console vs from the app server; thin, unicorn, nginx. I'll share any solution I come up with
Ok so removing these lines from config/boot.rb fixed this issue for me.
require 'yaml'
YAML::ENGINE.yamler = 'syck'
This had been placed there to fix an YAML parsing error, forcing YAML to use 'syck'. Removing this required me to fix the underlying issues with the .yml files. More on this here
Now my delayed job record handlers match between those created via the server (unicorn in my case) and the console. Both my server and delayed job workers are kicked off within bundler
Unicorn
cd #{rails_root} && bundle exec unicorn_rails -c #{rails_root}/config/unicorn.rb -E #{rails_env} -D"
DJ
export LANG=en_US.utf8; export GEM_HOME=/data/reception/current/vendor/bundle/ruby/1.9.1; cd #{rail
s_root}; /usr/bin/ruby1.9.1 /data/reception/current/script/delayed_job start staging

Resources