Ruby bind connection by net-ldap gem - ruby

I have some issue. I use net-ldap gem. When i trying bind connection, i have timeout error.
ldap = Net::LDAP.new :host => '1.1.1.1', :port => 389, :auth => { :method => :simple, :username => 'CN=LMS_User, OU=Service_Accounts, OU=TELE2, DC=JV,DC=MT-S,DC=KZ', :password => 'password' }
ldap.bind
Net::LDAP::Error: Connection timed out - user specified timeout
I used the ldap admin tool to check access with same data. The connection is established.
Tell me what am I doing wrong?

Related

Reading Emails via IMAP / SMTP through 'Mail' gem

Is there a way to receive emails via IMAP or SMTP through the 'mail' gem?
The documentation only seems to mention POP3:
Mail.defaults do
retriever_method :pop3, :address => "pop.gmail.com",
:port => 995,
:user_name => '<username>',
:password => '<password>',
:enable_ssl => true
end
The documentation actually talks directly about SMTP.
Mail.defaults do
delivery_method :smtp, address: "localhost", port: 1025
end
That is how you default to sending via SMTP.
To receive, instead of using delivery_method use retriever_method
IMAP works by simply adding this:
Mail.defaults do
retriever_method :imap, :address => 'imap.gmail.com',
:port => 993,
:user_name => '<username>',
:password => '<password>'
:enable_ssl => true
end
I'm still not able to get SMTP retrieval to work..

550 Cannot receive from specified address

I followed all the instructions on heroku and sendgrid but users receive an error when they try to sign up.
I ran the logs and here is the error.
What is wrong here?
2013-07-01 app[web.1]: Net::SMTPFatalError (550 Cannot receive from specified address <jay.mancho1#gmail.com>: Unauthenticated senders not allowed
my settings;
config/initializers/devise.rb
config.mailer_sender = "jay.mancho1#gmail.com"
config/environments/production.rb
config.action_mailer.default_url_options = { :host => '***.herokuapp.com' }
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => "25",
:authentication => :plain,
:user_name => ENV['***#heroku.com'],
:password => ENV['***'],
:domain => ENV['heroku.com']
}
You need to change the line where you are setting the username and password to be ENV['SENDGRID_USERNAME'] and ENV['SENDGRID_PASSWORD'], not your actual password. These values are stored on the server and should not appear in your code.

How to configure Devise email with Heroku and Sendgrid in Rails?

I've got a simple Rails 3.2.7 app with Devise added that is deployed to Heroku with Sendgrid added. It works fine on heroku for everything except when it needs to do a password retrieve which requires sending an email. From all the posts i have read i suspect i am somehow setting up the mail parameters incorrectly. Any suggestions are appreciated.
For config/environments/production.rb i added
config.action_mailer.default_url_options = { :host => 'smtp.sendgrid.net'}
for config/initializers/devise.rb i added
config.mailer_sender = "mail-to-send#from.com"
and for config/environments.rb i added
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
}
So, your problem is you were referencing the wrong environment variables. Heroku stores your SendGrid credentials in ENV['SENDGRID_USERNAME'] and ENV['SENDGRID_PASSWORD']. You were using your actual username and password as the key names.
This will work:
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
}

Binding to LDAP service

I'm using Ruby and trying to bind an LDAP server. The Ruby documentation seems to be very vague here and it's not obvious what I need to do after the following:
>> require 'uri'
=> true
>> newuri = URI::LDAP.build({:host => '10.1.1.1', :dc => 'cjndemo' , :dc => 'com', :user =>'admin', :password => 'Passw0rd'})
=> #<URI::LDAP:0x007fea9d0cef60 URL:ldap://10.1.1.1?>
What do I need to do to bind then query my LDAP service?
URI::LDAP is only for parsing and generating LDAP URIs. If you want to query the LDAP server you need to use a different tool like net-ldap or ruby-ldap.
An example of binding with simple authentication using net-ldap:
require 'net/ldap'
ldap = Net::LDAP.new(:host => '10.1.1.1',
:auth => {
:method => :simple,
:username => 'cn=admin,dc=cjndemo,dc=com',
:password => 'Passw0rd'
})
if ldap.bind
base = 'dc=cjndemo,dc=com'
filter = Net::LDAP::Filter.eq('objectclass', '*')
ldap.search(:base => base, :filter => filter) do |object|
puts "dn: #{object.dn}"
end
else
# authentication error
end

Error in SendGrid on Heroku cedar stack

when I try to send an email via sendgrid on heroku cedar stack,
I got an following error :
ArgumentError (SMTP-AUTH requested but missing user name):
my settings in /environments/staging.rb are :
config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'myapp' }
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => "587",
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com'
}
My Sendgrid password/username are obtained from Heroku according to this page
Does anyone have any suggestion ?
Try moving your config from config/enviornments/staging.rb into config/initializers/smtp.rb. That way you know ActionMailer is configured regardless of the environment you're in.
You should keep delivery specific setting in your environment files:
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true

Resources