I am using Rails 3 and implementing the email sending feature. I am not sure if my configuration is correct, but here are my codes:
mailers/user_mailer.rb
class UserMailer < ActionMailer::Base
default :from => "user#gmail.com"
def send_to(user)
#user = user
subject='welcome !'
mail(:to=>'y.lan#gmail.com', :subject=>subject, :content_type => "text/html")
mail.deliver
end
end
controller:
def CarsController < BaseController
...
def register_finish
UserMailer.send_to(user)
end
end
config/enviroment.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.googlemail.com",
:port => 532,
:arguments => '-i'
:enable_starttls_auto => true
}
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
When my controller invoke 'register_finish' function and try to send email to a user, I always get Timeout::Error (execution expired) error message, what could be the reason??
I saw some people define the configuration in config/initializers/setup_email.rb and use
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = { ...}
while I configure it in config/enviroment.rb and use:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {...}
I also saw some people invoke "deliver" method inside controller while I invoke it inside 'UserMailer'.
My questions:
What's the difference between my implementation and the above different way of implementations I found from internet.
Why I got timeout errors?
I'm also using gmail as my smtp server and I've adder setup_email.rb to initiliazers containing this code
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "domain.pl",
:user_name => "username",
:password => "password",
:authentication => "plain",
:enable_starttls_auto => true
}
and it works for me :)
EDIT
I've just notice we are using different servers, maybe try with my config?
Timeout errors mean that there is some authentication errors.
This line is no longer needed:
ActionMailer::Base.delivery_method = :smtp
While it is adviceable to set the smtp_settings in an initializer.
If you are using it on a development machine this configuration should work with gmail:
ActionMailer::Base.smtp_settings = {
:enable_starttls_auto => true,
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'your_domain',
:authentication => :plain,
:user_name => 'your_gmail_username',
:password => 'your_gmail_password'
}
EDIT
you can add for a development machine:
ActionMailer::Base.default_url_options[:host] = "localhost:3000"
Very good railscast on subject
Have a look at this:
http://lindsaar.net/2010/3/15/how_to_use_mail_and_actionmailer_3_with_gmail_smtp
Works nicely for me
Related
Net::SMTPAuthenticationError in Devise::ConfirmationsController#create
530-5.5.1 Authentication Required. Learn more at
I am using the gem 'devise'.
to send confirmation email with gmail account.
but, the error in title occur.
I searched many cases similar to my case and tried solutions in there, but those perfectly not worked, so I think my error has some different origin
( what I tried is : 1. less securing myaccount.google.com/u/1/security 2. http://www.google.com/accounts/DisplayUnlockCaptcha)
development.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
:authentication => :plain,
:address => "smtp.gmail.com",
:port => 587,
:domain => "mail.google.com",
:user_name => ENV["******#gmail.com"],
:password => ENV["******"],
:enable_starttls_auto => true
}
config.action_mailer.default_url_options = {:host => 'localhost:3000'}
top most error line in error page
def check_response(res)
unless res.success?
raise res.exception_class, res.message
end
end
please help me... TT
the problem your gmail setting, you should remove the ENV as you put string directly to it (as my understanding this is your local development this will generate an error since you also put config.action_mailer.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
:authentication => :plain,
:address => "smtp.gmail.com",
:port => 587,
:domain => "mail.google.com",
:user_name => "******#gmail.com",
:password => "******",
:enable_starttls_auto => true
}
I'm trying to send an email to administrator from the production environment, but failing to... It works in development with letter opener gem, but when I try in production, I'm getting the following error:
Net::SMTPAuthenticationError (530-5.5.1 Authentication Required. Learn more at app/controllers/contact_us_controller.rb:8:in `submit_form'
app/models/contact_form.rb:13:in `send_admin_notification'
My code for the submit_form action in the controller is:
def submit_form
#contact_form.attributes = contact_form_params
return redirect_to action: :thanks if #contact_form.save
render :index
end
and the code in the contact_form model is:
def send_admin_notification
AdminNotifier.contact_form(self).deliver_now
end
I've been struggling with this for the past 2 days so any help and guidance would much much appreciated
This works well for me on the production env:
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'gmail.com',
:user_name => 'koshlendra#gmail.com',
:password => 'secret_password',
:authentication => 'login',
:enable_starttls_auto => true
}
Try putting these configurations in your production.rb file
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { host:'yourhost'}
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'gmail.com',
:user_name => "your email",
:password => "yourpassword",
:authentication => :plain,
:enable_starttls_auto => true
}
This code fails to send email (nothing happens at all - no error either). What am I doing wrong?
/app/mailers/user_mailer.rb
class UserMailer < ActionMailer::Base
default from: "sample#gmail.com"
def email_test()
#user = 'recipient#gmail.com'
mail(to: #user, subject: 'Welcome to My Awesome Site')
end
end
/config/development.rb:
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_options = {from: 'no-reply#example.com'}
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:enable_starttls_auto => true,
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:authentication => :login,
:user_name => "sample#gmail.com",
:password => "password123",
}
I invoke the code in folder /app/mailers/. Here I run:
rails runner UserMailer.email_test
Is it because I am putting the gmail smtp settings in development.rb, but am running this code in command line?
I've already turned on 'access to less secure apps' in my gmail account. So confused, please advise thanks!
For Rails 3:
rails runner "UserMailer.email_test.deliver"
For Rails 4:
bin/rails runner "UserMailer.email_test.deliver_now"
Hi I am having a very strange problem. I setup mandrill as per the docs and I am now unable to send mail via my controller. Even devise mails do not seem to be going.... But I am able to send it via the console!
My Mail Config
config.action_mailer.default_url_options = { :host => 'smtp.mandrillapp.com' }
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.mandrillapp.com",
:port => 587,
:enable_starttls_auto => true,
:user_name => ENV["MANDRILL_USERNAME"],
:password => ENV["MANDRILL_APIKEY"],
:authentication => 'plain',
:domain => 'yim.mydomain.org',
}
My Mailer
class YimMailer < ActionMailer::Base
default from: "notifier#yim.mydomain.org"
def welcome_email(user, data)
#user = user
#data = data
mail(to: #user.email, subject: 'Welcome!')
end
end
In my controller:
YimMailer.welcome_email(current_user, dummydata).deliver
When i execute the same line via the console, it delivers. What could be the issue?
I am using rails 4
I had the same issue and restarted the server (accidentally), it started working via controller too!
I'm trying to setup devise 1.3.4 to send emails via gmail while in development mode. I should mention that I'm using Rails 3.0.4 and Ruby 1.9.2p136.
I've tried the following in config/environments/development.rb:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { :host => 'mydomain.com' }
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "mydomain.com",
:user_name => "info",
:password => "secret",
:authentication => "plain",
:enable_starttls_auto => true
}
And in config/initializers/devise.rb I changed
config.mailer_sender = "please-change-me-at-config-initializers-devise#example.com"
To
config.mailer_sender = "info#mydomain.com"
Then I tried
http://yekmer.posterous.com/devise-gmail-smtp-configuration
It's still not working.
Is there a wiki page on how to get the mailer working? I see the email in my log and it looks great! The links work, etc ... I just want to see them in my email account.
Edit
I found the answer -
I used http://yekmer.posterous.com/devise-gmail-smtp-configuration - I had been putting that code in config/intializers/devise.rb when I should have been putting it in config/environments/development.rb.
Have you tried this?
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "myinfo#gmail.com",
:password => "secret",
:authentication => "plain"
# :enable_starttls_auto => true # I don't have this, but it should work anyway
}
--------- EDIT
it it's sent maybe you don't receive it because of the spam filter, first thing to check:
class UserMailer < ActionMailer::Base
default :from => "myinfo#gmail.com"
# ...
end
you should put that in devise initializer :
# Configure the class responsible to send e-mails.
config.mailer = "YourAppDeviseMailer"
Then create a class that extends Devise::Mailer :
class YourAppDeviseMailer < Devise::Mailer
default :from => 'your_email'
def self.mailer_name
"devise/mailer"
end
end
I think you can change it inside config/initializers/devise.rb. No need for a new class I think?
#config/initializers/devise.rb
config.mailer_sender = 'youremail#gmail.com'
Check if the value of ActionMailer::Base.delivery_method is :smtp