In development.rb I have these ActionMailer settings:
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
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",
authentication: "plain",
enable_starttls_auto: true,
user_name: "username#gmail.com",
password: "password"
}
In notifier.rb (my mailer) I have these definitions:
def user_email(user)
#user = User.find(user)
mail(:to => user.email, :subject => "Welcome to me.")
end
def test_email
mail(:to => "here#there.com", :subject => "Test mail", :body => "Ain't I shapely?")
end
And running Notifier.test_email.deliver in the console gives me this: wrong number of arguments (0 for 1).
And running Notifier.user_email(2).deliver in the console gives me this: undefined method 'user_email' for Notifier:Class.
Am I missing something totally obvious here? The Gmail settings are all correct, but obviously the issue is before that.
Restarting the server fixed it. Nonsense.
Related
while sending email from the live server,
if i configure the smtp settings with gmail account it sends mail successfully,
config.action_mailer.default_url_options = { :host => 'myhostip' }
config.action_mailer.delivery_method = :smtp
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=> "mail.gmail.com",
:port=> 587,
:authentication=> "plain",
:enable_starttls_auto=> false,
:user_name=> "mymail#gmail.com",
:password=> "password"
}
if i configure the smtp settings with my server details it not sending mail, instead it throws error
Net::SMTPAuthenticationError (500 Unrecognized command)
this is triggered during sending confirmation email for user from device.
config.action_mailer.default_url_options = { :host => 'myhostip' }
config.action_mailer.delivery_method = :smtp
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=> "mail.mydomain.com",
:port=> 587,
:domain=> "mydomain.com",
:authentication=> "plain",
:enable_starttls_auto=> false,
:user_name=> "test#mydomain.com",
:password=> "pwd"
}
You've to use ActionMaliler::Base instead of config
ActionMailer::Base.smtp_settings #try this
config.action_mailer.smtp_settings #instead of this
Change your smtp code to below. It should work now.
ActionMailer::Base.smtp_settings = {
:address => 'path_to_address_specified_by_my_hoster',
:port => 25,
:domain => 'my_domain.com',
:authentication => :plain,
:user_name => 'signup#my_domain.com',
:password => 'password'
}
I have added a contact form to my site and am having a problem, when the message is sent I get my flash message, "successfully sent", however the email never arrives in my inbox. I am in development mode at the moment and my app/config file looks like this
class Application < Rails::Application
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "myemail#gmail.com",
:password => "example",
:authentication => :plain,
:enable_starttls_auto => true
}
config.action_mailer.default_url_options = {
:host => "gmail.com"
}
My contact Controller is like this
def new
#message = Message.new
end
def create
#message = Message.new(params[:message])
if #message.valid?
NotificationsMailer.new_message(#message).deliver
redirect_to(root_path, :notice => "Message was successfully sent.")
else
flash.now.alert = "Please fill all fields."
render :new
end
end
end
and finally my Notification Mailer
class NotificationsMailer < ActionMailer::Base
default :from => "myemail#gmail.com"
default :to => "myemail#gmail.com"
def new_message(message)
#message = message
if message.file
attachment_name = message.file.original_filename
attachments[attachment_name] = message.file.read
end
mail(:subject => "[myemail#gmail.com] #{message.subject}")
end
end
Am I missing anything obvious here as I have implemented this in another site which worked fine, just cant figure out what is going on
Any help appreciated
I know you set it in your app/config.rb, but I would ensure config.action_mailer.perform_deliveries isn't being overridden in your config/environments/development.rb
Is it possible to send mailers in the development environment?
I've added this to my development.rb file:
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.smtp_settings = {
:address => "mail.email.com",
:port => 25,
:domain => 'email.com',
:user_name => 'email#email.com',
:password => 'password',
:authentication => 'plain',
:enable_starttls_auto => true }
Then I run UserMailer.welcome_email(#user).deliver in rails console which returns #<Mail::Message:2265713480, Multipart: true, Headers: <Date: Thu... but I never actually receive the email. Is there something else I need to configure?
Oh, and if I check ActionMailer::Base.deliveries it returns an empty hash => [].
Needed to add the following to environments/development.rb:
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.perform_deliveries = true
facing problem in action mailer.
my mailer is
def registration_confirmation(user)
subject "Password Reset Instructions"
from "sender_email_id#test.com"
recipients user.email
content_type "text/html"
body "RESET your Password"
end
Settings for mailer are
require 'development_mail_interceptor'
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "domain.in",
:user_name => "admin#domain.in",
:password => "PASSWORD",
:authentication => "plain",
:enable_starttls_auto => true
}
ActionMailer::Base.default_url_options[:host] = "localhost:3000"
Mail.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?
and my controller is UserMailer.registration_confirmation(#new_user).deliver
The mail is not going to the user.email , it is always going to admin#domain.in
I am using mail-v 2.2.19 and rails 3.0.9
please help.
try adding this line(works for me):
mail(:to => user.email, :subject => "Password Reset Instructions")
to your registration_confirmation method
def registration_confirmation(user)
from "sender_email_id#test.com"
content_type "text/html"
body "RESET your Password"
mail(:to => user.email, :subject => "Password Reset Instructions")
end
I am a newbie to sending mails through rails. I have implemented devise in my project and now I want to send a welcome email and/or a password-reset email. What changes do I need to make in Devise views?
No errors are displayed, but still I don't receive any email.
I have followed the links specified below and finally my devise.rb, development.rb and production.rb files are as follows:
devise.rb
config.mailer_sender = "abc#gmail.com"
development.rb
config.action_mailer.raise_delivery_errors = false
config.action_dispatch.best_standards_support = :builtin
config.active_support.deprecation = :notify
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = false
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.active_support.deprecation = :log
config.action_mailer.smtp_settings ={
:enable_starttls_auto => true,
:address => 'smtp.gmail.com',
:port => 587,
:tls => true,
:domain => 'gmail.com',
:authentication => :plain,
:user_name => 'abc#gmail.com',
:password => '123456'
}
production.rb
config.action_mailer.default_url_options = { :host => 'gmail.com' }
config.active_support.deprecation = :notify
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors =false
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
:enable_starttls_auto => true,
:address => 'smtp.gmail.com',
:port => 587,
:tls => true,
:domain => 'gmail.com',
:authentication => :plain,
:user_name => 'abc#gmail.com',
:password => '123456'
}
When trying to send an email using rails in development environment, you'll see that in the configuration file for development, there is a line config.action_mailer.perform_deliveries = false which specifies whether mail will actually be delivered.
When you create a new rails project that parameter is automatically set to false, and if you want to actually send an email in development mode, you must (among other things) set that parameter to true