I've developed a Rails 3 app and I've recently added an action mailer for when a user signs up.
Testing it locally and it sends an email perfectly, but when I move it to the server at test it for a new user signing up, I get the following error.
I am running Nginx on the server with the original configurations, both local machine and server are running ubuntu 11.10
Net::SMTPAuthenticationError in UsersController#create
535-5.7.1 Username and Password not accepted.
app/controllers/users_controller.rb:26:in 'create'
In users_controller.rb - create - Line 26 is UserMailer.welcome_email(#user).deliver
def create
#user = User.new(params[:user])
if #user.save
sign_in #user
flash[:success] = "Welcome to University Sports!"
redirect_to #user
UserMailer.welcome_email(#user).deliver
else
#title = "Sign up"
render 'new'
end
end
In development.rb I have the following code:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'www.mydomain.co.uk',
:user_name => 'email#mydomain.co.uk',
:password => 'email_password',
:authentication => 'plain',
:enable_starttls_auto => true }
user_mailer.rb
class UserMailer < ActionMailer::Base
default :from => "univeristy.sports#louisgriffiths.co.uk"
def welcome_email(user)
#user = user
#url = "http://www.mydomain:3000"
mail(:to => user.email, :subject => "Welcome to University Sports")
end
end
I had the exact same error and found that my application.yml file was overriding it so I deleted that and now it works fine!
Related
I'm very new to Rails. Now I have a problem with sending reset password emails on Rails website.
Right now the problem is when I enter a registered email to reset the password, the email cannot be sent.
Net::OpenTimeout in PasswordResetsController#create
I think the problem is about the stmp setting.
Here is some of my code. By the way, I'm doing all these in the development environment.
development.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { :host =>
"http://localhost:3000" }
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => "587",
:domain => "Here I put my intern company",
# :domain => "gmail.com",
:authentication => :plain,
:user_name => "Here I put my actual email",
:password => "The password of my actual email",
:enable_starttls_auto => true
}
password_resets_controller.rb
def create
# #user = User.find_by(email: params[:password_resets]
[:email].downcase)
#user = User.find_by(email: params[:password_reset]
[:email].downcase)
if #user
#user.create_reset_digest
#user.send_password_reset_email
flash[:info] = "Email sent with password reset instructions"
redirect_to root_url
else
flash.now[:danger] = "Email address not found"
render 'new'
end
end
user.rb
def send_password_reset_email
UserMailer.password_reset(self).deliver_now
end
user_mailer.rb
class UserMailer < ApplicationMailer
default from: "naomi<noreply#MYINTERNCOMPANY.com>"
def password_reset(user)
#user = user
mail(to: #user.email, subject: 'Password reset')
end
end
application_mailer.rb
class ApplicationMailer < ActionMailer::Base
default from: 'noreply#MYINTERNCOMPANY.com'
layout 'mailer'
end
Can anyone help with this?
And also, after this how can I set the production environment so that the website can be deployed on Heroku?
I am following Rails Tutorial on Chapter 10.
Since I do not have credit card, I am trying to send the email in development. I am newbie to programming, so I just want to see how it works.
But, I am getting this error.
Net::SMTPAuthenticationError (530-5.5.1 Authentication Required. Learn more at
):
app/models/user.rb:65:in `send_password_reset_email'
app/controllers/password_resets_controller.rb:13:in `create'
Rendered /home/budi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/web-console-2.0.0.beta3/lib/action_dispatch/templates/rescues/_source.erb (5.3ms)
Rendered /home/budi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/web-console-2.0.0.beta3/lib/action_dispatch/templates/rescues/_trace.html.erb (2.6ms)
Rendered /home/budi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/web-console-2.0.0.beta3/lib/action_dispatch/templates/rescues/_request_and_response.html.erb (1.1ms)
Rendered /home/budi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/web-console-2.0.0.beta3/lib/action_dispatch/templates/rescues/_web_console.html.erb (0.9ms)
Rendered /home/budi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/web-console-2.0.0.beta3/lib/action_dispatch/templates/rescues/diagnostics.html.erb within rescues/layout (30.9ms)
could somebody show me where I missed?
development.rb
config.cache_classes = false
config.eager_load = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'mail.google.com',
:user_name => ENV['#I hardcoded it here'], # I put my my email which I used regularly here.
:password => ENV['#I hardcoded it here'], # I put the password here.
:authentication => 'plain',
:enable_starttls_auto => true
}
config.active_support.deprecation = :log
config.active_record.migration_error = :page_load
config.assets.debug = true
config.assets.digest = true
config.assets.raise_runtime_errors = true
user_mailer.rb
class UserMailer < ApplicationMailer
def account_activation(user)
#user = user
mail to: user.email, subject: "Account activation"
end
def password_reset(user)
#user = user
mail to: user.email, subject: "Password reset"
end
end
application_mailer.rb
class ApplicationMailer < ActionMailer::Base
#default from: "from#example.com"
default from: "xxxxxx#gmail.com" # I put my my email which I used regularly here.
layout 'mailer'
end
password_reset_controller.rb
class PasswordResetsController < ApplicationController
before_action :get_user, only: [:edit, :update]
before_action :valid_user, only: [:edit, :update]
before_action :check_expiration, only: [:edit, :update]
def new
end
def create
#user = User.find_by(email: params[:password_reset][:email].downcase)
if #user
#user.create_reset_digest
#user.send_password_reset_email
flash[:info] = "Email sent with password reset instructions"
redirect_to root_url
else
flash.now[:danger] = "Email address not found"
render 'new'
end
end
def edit
end
def update
if params[:user][:password].empty?
#user.errors.add(:password, "can't be empty")
render 'edit'
elsif #user.update_attributes(user_params)
log_in #user
flash[:success] = "Password has been reset."
redirect_to #user
else
render 'edit'
end
end
private
def user_params
params.require(:user).permit(:password, :password_confirmation)
end
def get_user
#user = User.find_by(email: params[:email])
end
# Confirms a valid user.
def valid_user
unless (#user && #user.activated? && #user.authenticated?(:reset, params[:id]))
redirect_to root_url
end
end
# Checks expiration of reset token.
def check_expiration
if #user.password_reset_expired?
flash[:danger] = "Password reset has expired."
redirect_to new_password_reset_url
end
end
end
Hope you do not set user name and password in environment variable ENV instead you write it ENV["the actual user name"]
so it did not pass that.
and try gmail.com if you want to sent it via gmail
You can use
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "test#gmail.com" #your gmail id
:password => "1234" #your gmail password
:authentication => :plain,
:enable_starttls_auto => true
}
or if you want to set the password in env
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "gmail.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"]
}
If you’re familiar with Unix, you’ve likely had experience setting
environment variables. Unix environment variables are typically set in
a file that is read when starting an interactive shell (the ~/.bashrc
file for the bash shell).
For a bash
shell, edit the ~/.bashrc file and add:
export GMAIL_USERNAME="myname#gmail.com"
export GMAIL_PASSWORD="mypassword"
I would like to suggests you to follow up with
Railsapps -Send Mail and
Railsapps -rails-environment-variables
Would Definitely help You
Edit Update
Allow less secure apps to access accounts
Google may block sign-in attempts from some apps or devices that do
not use modern security standards. Since these apps and devices are
easier to break into, blocking them helps keep your account safe.
Some examples of apps that do not support the latest security
standards include:
The Mail app on your iPhone or iPad with iOS 6 or below The Mail app
on your Windows phone preceding the 8.1 release Some Desktop mail
clients like Microsoft Outlook and Mozilla Thunderbird
Hi I'm trying to create simple app. After devise user is logged in can create event as soon as create this email will be send to him.
def create
#event = Event.new(event_params)
#event.user = current_user
#event.save
#user= current_user
UserMailer.welcome_email(#user).deliver
respond_with(#event)
end
I've change on production and development files
config.action_mailer.default_url_options = { :host => 'https://mydomiantest.io' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:user_name => 'username',
:password => 'mypassword',
:domain => 'mydomiantest.io',
:address => 'smtp.sendgrid.net',
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}
I've also created user_mailer.rb in mailers
class UserMailer < ActionMailer::Base
default from: 'no-replay#mytestsite.io'
def welcome_email(user)
#user = user
#url = 'mytestsite.io'
mail(to: #user.email, subject: 'Welcome to My Awesome Site')
end
end
It is takes some time after creating event and then I don't have any email, I have created account on site grid what else do I need to do?
In my ROR app, I am trying to send confirmation emails to my registered users when they signup, my website is on localhost currently. I am getting this error:
"undefined method `recipients' for #<UserMailer:0x3d841a0>"
Here is my code;
development.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => "localhost:3000"}
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => "587",
:authentication => :login,
:user_name => "myemailid#gmail.com",
:password => "myrealpassword"
}
Users_controller.rb
def new
UserMailer.registration_confirmation(#user).deliver
end
def create
#user = User.new(params[:user])
if #user.save
UserMailer.registration_confirmation(#user).deliver
sign_in #user
flash[:success] = "Welcome!"
redirect_to #user
else
render 'new'
end
end
user_mailer.rb
class UserMailer < ActionMailer::Base
def registration_confirmation(user)
recipients user.email
from "myemailid#gmail.com"
subject "Thank you for registration"
body :user => user
end
end
** development.rb**
config.action_mailer.delivery_method = :sendmail
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
** Users_controller.rb **
def new
UserMailer.registration_confirmation(#user).deliver
end
def create
#user = User.new(params[:user])
if #user.save
UserMailer.registration_confirmation(#user).deliver
sign_in #user
flash[:success] = "Welcome!"
redirect_to #user
else
render 'new'
end
end
** User_mailer.rb **
def registration_confirmation(user)
#message = 'whatever you want to say here!'
mail(:from => "myemailid#gmail.com", :to => user.email, :subject => "Thank you for registration")
end
**/app/views/user_mailer/registration_confirmation.text.erb *
<%= #message %>
That's what I've done in my development mode, and it works
What version of Rails are you using?
Sending of email changed in version 3.2 (I believe)
http://api.rubyonrails.org/classes/ActionMailer/Base.html
Try:
UserMailer.registration_confirmation(#user).deliver
This is your user_mailer.rb
user_mailer.rb
class UserMailer < ActionMailer::Base
def registration_confirmation(user)
recipients user.email
from "myemailid#gmail.com"
subject "Thank you for registration"
body :user => user
end
Try instead:
class UserMailer < ActionMailer::Base
default from: "myemailid#gmail.com"
def registration_confirmation(user)
mail(to: user.email, subject: "Thank you for registration")
end
end
And set up the appropriate view in views/user_mailer e.g. registration_confirmation.html.erb
Ok, i'm a total newbie so please forgive me in advance.
I want to create a very simple rails application. I've created a button that's supposed to send an email to myself. I've had no previous Rails experience so any help you can give is much appreciated.
Here's what I've done so far:
config/environment.rb:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'baci.lindsaar.net',
:user_name => 'myUsernameHere',
:password => 'myPassHere',
:authentication => 'plain',
:enable_starttls_auto => true }
controllers/posts_controller.rb:
def sendMessage
UserMailer.welcome_email().deliver
respond_to do |format|
format.html { render :nothing => true, :status => :ok }
end
end
app/mailers/user_mailer.rb:
class UserMailer < ActionMailer::Base
def welcome_email()
mail(:to => '<my email address here>',
:subject => "Welcome to My Site")
end
end
I've also created the email template in views/user_mailer/welcome_email.html.erb
The problem: I click on the button and I don't receive an email.
Thank you very much in advance.
Matt
In MycontrollerController send_mail is action so this is wrong def send_email(address) just define
def send_email(address)
#address = params[:address]
PostMailer.test_email(#address).deliver
end
I think that is what the above error is
nevermind, i was forgettting
default :from => "<email address here>"
in app/mailers/user_mailer.rb
it works now.