Reputation: 259
I am trying to send mail in production environment as follow:
in user-mailer.rb:
class UserMailer < ActionMailer::Base
default to: "[email protected]"
def feedBack_mail(email,message)
@mess=message
@url = 'http://www.google.com'
mail(from: email, subject: 'new_feedback')
end
end
in feedback_mail.text.erb
<%= @mess %>
in user_controller.rb
def create
respond_to do |format|
@client= params[:client]
if UserMailer.feedBack_mail(params[:email],params[:message]).deliver
format.json { render json: @client, status: :created, location: @client }
else
format.json {render json: @client.errors, status: :unprocessable_entity}
end
end
end
in production.rb I add this configuration:
if config.respond_to?(:action_mailer)
# config.action_mailer.raise_delivery_errors = false
config.action_mailer.default_url_options = { :host => 'monsite.com' }
# ActionMailer Config
# Setup for production - deliveries, no errors raised
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 = {
address: "smtp.gmail.com",
port: 25,
domain: "monsite.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"]
}
end
what I got in production.log
I, [2015-02-17T15:38:05.436159 #2003552] INFO -- : Started POST "/feedback/send.json" for 197.14.10.26 at 2015-02-17 15:38:05 +0100
I, [2015-02-17T15:38:05.473826 #2003552] INFO -- : Processing by UsersController#create as JSON
I, [2015-02-17T15:38:05.473943 #2003552] INFO -- : Parameters: {"email"=>"[email protected]", "message"=>"qerfsertq", "user"=>{"email"=>"[email protected]", "message"=>"qerfsertq"}}
I, [2015-02-17T15:38:05.524701 #2003552] INFO -- : Rendered user_mailer/feedBack_mail.text.erb (0.5ms)
I, [2015-02-17T15:38:08.673302 #2003552] INFO -- :
Sent mail to [email protected] (755.5ms)
I, [2015-02-17T15:38:08.674260 #2003552] INFO -- : Completed 201 Created in 3200ms (Views: 0.3ms | ActiveRecord: 0.0ms)
But I do not get any mail sent to [email protected] not even as spam
I really could not understand where's the problem
Upvotes: 2
Views: 681
Reputation: 259
I solved the problem by creating a Mandrill
account and changing the configuration like follow:
config.action_mailer.smtp_settings = {
:port => '587',
:address => 'smtp.mandrillapp.com',
:user_name => 'xxxxxxxx',
:password => 'xxxxxx',
:domain => 'domain.com',
:authentication => :plain
}
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { host: "monsite.com" }
Upvotes: 1