ActiveAdmin not sending password confirmation instructions - ruby-on-rails-3.1

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
}

Related

Automation of email sending process through corporate webmail

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).

Sending email from simple Sinatra app using Pony

I am building my first portfolio page with Sinatra.
I have a 'textbook' contact page with a straight-forward form containing 'name', 'email' and 'content' fields. When someone submits the form, I want to recieve an email notification.
Pony claims that it can send email via simple 'one-line' of code. I have read the Pony documentation but it is not very detailed in how to set it up.
I don't know if I am not setting it up properly, the code is not right, Pony is not the best tool, or if my development environment is not allowing the mail to be sent.
The code below is supposed to be sending an email from the post method, it is then saving the data to a PostgreSQL database via the save_message method. The data is being persisted correctly.
#server.rb
require 'sinatra'
require 'pony'
require_relative 'model/methods'
get '/contact' do
erb :contact
end
post '/thankyou' do
unless params[:name] == '' || params[:email] == '' || params[:content] == ''
Pony.options = {
:subject => "Portfolio page: Message delivery from #{params[:name]}",
:body => "#{params[:content]}",
:via => :smtp,
:via_options => {
:address => 'smtp.1and1.com',
:port => '587',
:enable_starttls_auto => true,
:user_name => ENV["USER_EMAIL_ADDRESS"],
:password => ENV["SMTP_PASSWORD"],
:authentication => :login,
:domain => 'nterrafranca.com'
}
}
Pony.mail(:to => ENV["DESTINATION_EMAIL_ADDRESS"])
save_message(params[:name], params[:email], params[:content])
end
redirect '/'
end
Pony needs to know how to send the email, not just who it's to, from, what the subject and body are, etc.
From the pony documentation, it will default to use sendmail, otherwise configures SMTP to use localhost. Depending on where this application is running, it's highly likely that sendmail is not available, and that there is no SMTP configured on localhost.
I've used Pony for several applications. Each one, I configure a "noreply#" email address for Pony to use to authenticate for SMTP, therefore using my own domain email (usually Google Apps, or even Gmail) for my SMTP connection. For example:
Pony.options = {
:subject => "Some Subject",
:body => "This is the body.",
:via => :smtp,
:via_options => {
:address => 'smtp.gmail.com',
:port => '587',
:enable_starttls_auto => true,
:user_name => 'noreply#cdubs-awesome-domain.com',
:password => ENV["SMTP_PASSWORD"],
:authentication => :plain, # :plain, :login, :cram_md5, no auth by default
:domain => "localhost.localdomain"
}
}
In the case of a Sinatra app, I perform the exact above code (with the obvious substitutions) right before I call:
Pony.mail(:to => <some_email>)
I've configured Pony multiple times - comment if you still have issues and I'll be glad to help.
If you are using a gmail account with 2-step verification, you must generate an application specific password for the Pony mailer, and NOT use your usual SMTP password.
See https://support.google.com/accounts/answer/185833?hl=en
Insert the application specific password in the place of your usual password.
This is from the Pony project page on Github.

Getting email to work on openshift ruby application

I can't seem to get email for password recovery using devise to work on my openshift app. I'm using Rails 4.0.2 and Ruby 1.9.3. I've tried the following in production.rb :
config.action_mailer.default_url_options = { :host => 'mydomain.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:port => 25,
:address => 'smtp.mailgun.org',
:user_name => 'postmaster#domain.com',
:password => '[password]',
:domain => 'mydomain.com.mailgun.domain',
:authentication => :plain,
}
I've also done settings required for google use and both worked fine in development on local. Also tried ports 465, 587, as described here. Sending mail unfortunately still isn't performed on production. The app just throws an error with nothing in the logs.

message not delivered to email -ruby on rails-

i tried to send message to mail by using ruby on rails but it not delivered
Although 0 error in the code
mail(:to => user.email, :subject => "Welcome to My site")
con
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "username",
:password => "password",
:authentication => "plain",
:enable_starttls_auto => true
}
RegistedMailer.sendingmail(#profolio).deliver
note
the application buit on localhost
What is the setting for delivery method ? It should be:
config.action_mailer.delivery_method = :smtp
In development mode, Rails does not send out the email. Make sure you set this, per the Rails Guides Action Mailer Configuration for GMail page:
config.action_mailer.delivery_method = :smtp
If that's already set, can you post your log?
You may also want to investigate something like MailCatcher, which makes it easier to test emails in development mode.

Capistrano - Email pending changes after deploy

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`

Resources