I am student from salzburg.
I am trying to create a login possibility via ldap with omnitauth-ldap, when I enter username and password it is redirecting to /auth/failure with message=invalid_credentials and I don't know why. Facebook-, Twitter- and BrowserID-Login is working.
Ruby-Version: 1.9.2
Omni-Auth-Version: 1.0.1
Omniauth-Ldap-Version: 1.0.2
omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :browser_id
provider :facebook, '34234234234', '23423421234123412342134'
provider :twitter, 'dfgsdfgsdfg', '2334sadfasdfasdf'
provider :ldap, :title => 'FH-Authentifizierung',
:host => 'denise.core.fh-salzburg.ac.at',
:port => 636,
:method => :plain,
:base => 'o=fh-salzburg.ac.at,o=FHS',
:uid => 'uid',
:password => "password",
:try_sasl => false,
:bind_dn => "anonymous"
end
users_controller.rb
class UsersController < ApplicationController
def create
auth = request.env["omniauth.auth"]
user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth)
session[:user_id] = user.id
redirect_to request.referer, :notice => "Herzlich Willkommen!"
end
def destroy
session[:user_id] = nil
redirect_to request.referer, :notice => "Du wurdest erfolgreich abgemeldet!"
end
end
server-output
Started POST "/auth/ldap/callback" for 127.0.0.1 at 2012-01-03 21:59:35 +0100
Started GET "/auth/failure?message=ldap_error" for 127.0.0.1 at 2012-01-03 21:59:35 +0100
Started GET "/auth/failure?message=invalid_credentials" for 127.0.0.1 at 2012-01-03 21:59:35 +0100
Started GET "/auth/failure?message=invalid_credentials" for 127.0.0.1 at 2012-01-03 21:59:35 +0100
If you look at the omniauth-ldap code you will see that bind_dn and password are used for authentication, so they need to be valid. If you want anonymous access omit those two parameters, or set :allow_anonymous to true.
Related
I'm working on a webscraper that will send out a weekly CSV with new content with Ruby. For the mailing component I decided to use the Mail gem. After a great deal of tinkering I got it to send a few test emails. However, I frequently get this error:
...smtp.rb:541:in `initialize': execution expired (Net::OpenTimeout)...
I have a reasonable internet connection and haven't been able to detect any sort of pattern with the error. Here is my code for the mailer:
require 'mail'
def sendEmail(newEventCount, newEventArray)
if newEventArray.to_a.empty? == true
emailBodyText = "No new events were added this week."
else
newEventString = "The new events are: "
newEventArray.each do |event|
newEventString = newEventString + event + "\n"
end
emailBodyText = "#{newEventCount} events were added this week. #{newEventString}"
end
options = { :address => "smtp.gmail.com",
:port => 587,
:domain => '(my public ip address according to google)',
:user_name => '(my username)',
:password => '(my password)',
:authentication => 'plain',
:enable_starttls_auto => true }
Mail.defaults do
delivery_method :smtp, options
end
mail = Mail.new do
from '(my email)'
to '(recipient email)'
subject 'Weekly Scrape Results'
body emailBodyText
add_file './events.csv'
end
mail.deliver!
end
I am in need of a script which automatically sends particular data from my corporate webmail email id .
Till now I am able to send automatic emails from a gmail id. But Iam unable to configure it for my webmail id.
Please let me know if any configuration changes are needed or I need to setup a server for this.(if possible also help me how to configure the server)
This is the Ruby function which I am using
def send_mail(to_recepient,data,mailSubject,extraBodyText,sender_info)
options = { :address => "smtp.gmail.com",
:port => 587,
:domain => 'mail.gmail.com',
:user_name => sender_info[:senderName],
:password => sender_info[:senderPassword],
:authentication => 'plain',
:enable_starttls_auto => true }
Mail.defaults do
delivery_method :smtp, options
end
Mail.deliver do
to "#{to_recepient}"
from 'mailtest20152#gmail.com'
subject mailSubject
body stringData
fh=File.open('attachment_file',"w")
fh.puts data
add_file :filename => 'attachment_file', :content => data
end
File.unlink('attachment_file')
end
I faced similar problem. You can configure mailer for particular smtp server like this:
options = { :address => "smtp.yourdomain.com", #address can differ
:port => 25 }
Don't forget to add:
config.action_mailer.delivery_method = :smtp
Don't need to provide password and username, but remember to specify from field in your email message (as you already did).
I recently installed ActiveAdmin and I am working on the User model. After I created the initial AdminUser I tried adding another AdminUser and its supposed to send an email to set up the password but it fails to send the email.
I have this code in my config/development folder
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
and this in my AdminUser model
after_create { |admin| admin.send_reset_password_instructions }
def password_required?
new_record? ? false : super
end
Not sure why its not sending the email for me to change my password.
You are getting problem because you didn't configure any server to go out an emails.
You are on right path. just add following things.
Please add following line to app/Gemfile and run bundle install.
gem "letter_opener"
and then add following line to config/enviornments/development.rb
config.action_mailer.delivery_method = :letter_opener
Above code will help you to see the result in the browser itself, doesn't actually sends the email.
To send an actual email you need to change following line and need to add smtp code.(smtp server)
config.action_mailer.delivery_method = :smtp
Then add following lines below above line:
config.action_mailer.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => 587,
:domain => 'gmail',
:user_name => 'gmail username',
:password => 'gmail password',
:authentication => 'plain',
:enable_starttls_auto => true
}
I've been using this gist to send an email after deployment but I'd like the message to contain the pending changes.
I can't quite figure out how to get the get the response from cap deploy:pending into a variable that can be added to the email message.
https://gist.github.com/955917
How to use it?
1. Add this file to config/deploy folder.
2. Update the file with your google credentials and from email address.
3. Add the following content to config/deploy.rb.
require 'config/deploy/cap_notify.rb'
# add email addresses for people who should receive deployment notifications
set :notify_emails, ["EMAIL1#YOURDOMAIN.COM", "EMAIL2#YOURDOMAIN.COM"]
after :deploy, 'deploy:send_notification'
# Create task to send a notification
namespace :deploy do
desc "Send email notification"
task :send_notification do
Notifier.deploy_notification(self).deliver
end
end
4. Update deploy.rb with destination email addresses for the notifications.
5. To test run this command:
cap deploy:send_notification
=end
require "action_mailer"
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:enable_starttls_auto => true,
:tls => true,
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:authentication => "plain",
:user_name => "YOUR USER NAME",
:password => "YOUR PASSWORD"
}
class Notifier < ActionMailer::Base
default :from => "YOUR FROM EMAIL"
def deploy_notification(cap_vars)
now = Time.now
msg = "Performed a deploy operation on #{now.strftime("%m/%d/%Y")} at #{now.strftime("%I:%M %p")} to #{cap_vars.host}"
mail(:to => cap_vars.notify_emails,
:subject => "Deployed #{cap_vars.application} to #{cap_vars.stage}") do |format|
format.text { render :text => msg}
format.html { render :text => "<p>" + msg + "<\p>"}
end
end
end
Just use backticks?
str = `cap deploy:pending`
I'm writing a small Ruby program that will pull records from a database and send an HTML email daily. I'm attempting to use ActionMailer 3.0.3 for this, but I'm running in to issues. All the searching I've done so far on using ActionMailer outside of Rails applies to versions prior to version 3. Could someone point me in the right direction of where to find resources on how to do this? Here's where I am so far on my mailer file:
# lib/bug_mailer.rb
require 'action_mailer'
ActionMailer::Base.delivery_method = :file
class BugMailer < ActionMailer::Base
def daily_email
mail(
:to => "example#mail.com",
:from => "example#mail.com",
:subject => "testing mail"
)
end
end
BugMailer.daily_email.deliver
I'm definitely stuck on where to put my views. Every attempt I've made to tell ActionMailer where my templates are has failed.
I guess I should also ask if there's a different way to go about accomplishing this program. Basically, I'm doing everything from scratch at this point. Obviously what makes Rails awesome is it's convention, so is trying to use parts of Rails on their own a waste of time? Is there a way to get the Rails-like environment without creating a full-blown Rails app?
After some serious debugging, I found how to configure it.
file mailer.rb
require 'action_mailer'
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "domain.com.ar",
:authentication => :plain,
:user_name => "test#domain.com.ar",
:password => "passw0rd",
:enable_starttls_auto => true
}
ActionMailer::Base.view_paths= File.dirname(__FILE__)
class Mailer < ActionMailer::Base
def daily_email
#var = "var"
mail( :to => "myemail#gmail.com",
:from => "test#domain.com.ar",
:subject => "testing mail") do |format|
format.text
format.html
end
end
end
email = Mailer.daily_email
puts email
email.deliver
file mailer/daily_email.html.erb
<p>this is an html email</p>
<p> and this is a variable <%= #var %> </p>
file mailer/daily_email.text.erb
this is a text email
and this is a variable <%= #var %>
Nice question! It helped me to understand a bit more how Rails 3 works :)
It took me a while to get this to work in (non-)Rails 4. I suspect it's just because I have ':require => false' all over my Gemfile, but I needed to add the following to make it work:
require 'action_view/record_identifier'
require 'action_view/helpers'
require 'action_mailer'
Without the above code, I kept getting a NoMethodError with undefined method 'assign_controller'.
After that, I configured ActionMailer as follows:
ActionMailer::Base.smtp_settings = {
address: 'localhost', port: '25', authentication: :plain
}
ActionMailer::Base.default from: 'noreply#example.com'
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.logger = Logger.new(STDOUT)
ActionMailer::Base.logger.level = Logger::DEBUG
ActionMailer::Base.view_paths = [
File.join(File.expand_path("../../", __FILE__), 'views', 'mailers')
# Note that this is an Array
]
The templates go in lib/<GEM_NAME>/views/mailers/<MAILER_CLASS_NAME>/<MAILER_ACTION_NAME>.erb (MAILER_ACTION_NAME is the public instance method of your mailer class that you call to send the email).
Lastly, don't forget to put this in your spec_helper:
ActionMailer::Base.delivery_method = :test