According to my problem I posted here: mailer error in production only I decided to create a small scaffold app to find a solution.
The problem:
I can't send (newsletter)email with smtp in production, but it works perfectly in development.
You can find the app in my github repository.
I just created a contact_messages scaffold and a simple mailer.
The error log after clicking on the submit button to receive email:
Started POST "/contact_messages" for 194.XXX.XX.XXX at 2013-02-26 19:43:59 +0000
Processing by ContactMessagesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"xx0nxxJ2xwxxJavvZ278EUy2TABjD9CixxNcxDqwg=",
"contact_message"=>{"name"=>"test", "email"=>"test#testemail.com", "message"=>"test1"}, "commit"=>"Create Contact message"}
Rendered contact_mailer/confirmation.text.erb (0.3ms)
Sent mail to test#testemail.com (38ms)
Completed 500 Internal Server Error in 100ms
Errno::ECONNREFUSED (Connection refused - connect(2)):
app/controllers/contact_messages_controller.rb:46:in `create'
The emails get saved, they are listed in the index. So the database should work fine.
I'm using Ubuntu 12.04, Apache, Phusion Passenger, SMTP with Gmail Account.
Could this probably be a server issue, or am I doing something wrong in the app?
I'm using fail2ban and denyhost. Could these tools block smtp?
Any help will be appreciated, thanks!
By default, Rails sends email by connecting to the target SMTP server. Try using sendmail instead. Add this in your config/initializers/production.rb:
config.action_mailer.delivery_method = :sendmail
I solved my problem with a change to a new passwort (api-key) from mandrill. Still don't know what the problem was, because with the old one it worked in development mode...
The working setting:
YourApp::Application.configure do
config.action_mailer.smtp_settings = {
:address => "smtp.mandrillapp.com",
:port => 587,
:enable_starttls_auto => true,
:user_name => "MANDRILL_USERNAME",
:password => "MANDRILL_PASSWORD", # SMTP password is any valid API key
:authentication => 'login'
}
Related
First, let me specify that I am aware that ActionMailer does NOT send emails by default in development mode.
Also, I took a look at similar questions, and none of them was relevant to my situation.
So, here we go:
I am following this Site Point tutorial by Ilya Bodrov-Krukowski, from March 26, 2015 in order to install and setup Devise on my Rails 4 app.
Because we activated Devise's confirmable module, I need to send emails in development to allow users who signup to activate their account and login.
Whenever I create a new user (through http://localhost:3000/users/sign_up), I do get the following alert:
A message with a confirmation link has been sent to your email
address. Please follow the link to activate your account.
However, I never actually receive the email with the confirmation link.
——————————
UPDATE
In my development.log file, I can see that the email was "sent":
Devise::Mailer#confirmation_instructions: processed outbound mail in 172.1ms
Sent mail to hello#mydomain.com (54.4ms)
Date: Tue, 25 Aug 2015 12:15:15 -0700
From: contact#anotherdomain.com
Reply-To: contact#anotherdomain.com
To: hello#mydomain.com
Message-ID: <55dcbec3a1ef8_33b93fcffc4988f493685#XXXXXX.local.mail>
Subject: Confirmation instructions
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<p>Welcome hello#mydomain.com!</p>
<p>You can confirm your account email through the link below:</p>
<p>Confirm my account</p>
[1m[35m (0.8ms)[0m commit transaction
Redirected to http://localhost:3000/
Completed 302 Found in 560ms (ActiveRecord: 1.7ms)
And, when I copy and paste the link from the log into my browser, then I get the following alert:
Signed in successfully.
So, it seems the only thing that is not working is the actual sending / receiving of the email.
——————————
As recommended in the tutorial, I followed Rails documentation regarding ActionMailer configuration and here is what I have in my config/environments/development.rb file:
config.action_mailer.delivery_method = :sendmail
# Defaults to:
# config.action_mailer.sendmail_settings = {
# location: '/usr/sbin/sendmail',
# arguments: '-i -t'
# }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_options = {from: 'hello#mydomain.com'}
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
Obviously, I am missing something, but I cannot figure out what (I am very, very junior with Rails).
Any idea?
Mail is not sent in development by default. To enable this you have to set config.action_mailer.perform_deliveries = true in development.rb file which I see you already have.
You may also have to enable config.action_mailer.raise_delivery_errors = true to raise delivery errors. That way, you will be able to see if there are any errors in the email delivery process.
Also, double check your default from if that has a valid email.
Also try switching the delivery method to sendmail:
config.action_mailer.delivery_method = :sendmail
This should solve your issue.
You need a mail server for Action Mailer to send emails.
such as
MailGun
which has a free account and a gem which makes set up easy.
mailgun_rails
I've set up Honeybadger almost a year ago and so far it works like a charm registering errors on my production and staging environments.
Then I decided to make a custom error behavior in controller. I am using the code similar to:
begin
params = {
:id => 1,
:class => MyClass,
:foo => "bar"
}
my_unpredicable_method(*params)
rescue => e
Honeybadger.notify(
:error_class => "Special Error",
:error_message => "Special Error: #{e.message}",
:parameters => params
)
end
which is described here.
I was going to test in local environmet to tune error messages, passing params, etc.
But the problem is when I receive the error (I am sure that I receive it, tested with debugger) nothing is sent to honeybadger website. Meanwhile, rake honeybadger:test works fine and sends the testing error messages to the server from localhost. Also, this custom notification works if I push it to testing environment on Heroku.
The question is:
What should I do to send this custom error to honeybadger from localhost?
Thank you in advance.
I found a solution. We need to add the following option to honeybadger initializer:
config.development_environments = %w(test)
This option is the list of environments in which notifications should not be sent and by default development in the list. See detailed explanation of the configuring option here.
Please add following configuration in config/honeybadger.yml
development:
report_data: true
Please read https://github.com/honeybadger-io/honeybadger-ruby#configuration-options
I want to render received emails (via SMTP Server) that are stored in my DB and my question is:
Is there a gem that provides rendering html_part, text_part from incoming email (received via SMTP Server) or something that can help to render an email depending which type it is (HTML, TEXT) ?
with best regards
Hannes
yes there is a very beautiful gem mailcatcher here github link
Instructions:
1) install the gem configure it by replacing your default setting with
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 }
2) open terminal type mailcatcher enter.
3) send email.
4) now open browser and go to this address localhost:1080.
you will see that you have received email.
MailView from 37signals allows you to render Mailer objects and view them from your browser.
I'm trying to send emails in a Rails app. It works if I use Gmail, but it's not working if I use Mandrill. I'm getting this timeout error with Mandrill. Not sure what I'm doing wrong. With both Gmail and Mandrill I am setting the username and password/api_key using environment variables. The only difference between the two setups is what you see below. Any ideas?
Timeout::Error in RegistrationsController#create
execution expired
Rails.root: /Users/michaeljohnmitchell/Sites/pre
Application Trace | Framework Trace | Full Trace
app/models/user.rb:38:in `send_welcome_email'
Mandrill Doesn't work
config.action_mailer.smtp_settings = {
:address => "smtp.mandrillapp.com",
:port => 25,
:user_name => ENV["MANDRILL_USERNAME"],
:password => ENV["MANDRILL_API_KEY"]
}
Gmail Works
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"]
}
use port 587 for mandrill, happend the same to me :)
this is because port 25 is sending plain text and port 587 sends SSL encoded emails (which I think is the whole mandrill idea).
I have no idea why they set it to port 25 in their examples.
Here are a few things you can try based on the information you provided:
make sure the correct information is in each of your environment files (production.rb and development.rb)
try hardcoding the username and password for mandrill as opposed to using environmental variables (for testing only)
In my rails application I am trying to send mail using custom from address.
It works fine few times, but most of the time it doesn't work.
I am getting the following smtp error message
Net::SMTPFatalError (553 Sorry, your envelope sender is in my badmailfrom list.
):
C:/Ruby/lib/ruby/1.8/net/smtp.rb:687:in `check_response'
C:/Ruby/lib/ruby/1.8/net/smtp.rb:660:in `getok'
C:/Ruby/lib/ruby/1.8/net/smtp.rb:638:in `mailfrom'
C:/Ruby/lib/ruby/1.8/net/smtp.rb:550:in `send0'
C:/Ruby/lib/ruby/1.8/net/smtp.rb:475:in `sendmail'
/vendor/rails/actionmailer/lib/action_mailer/base.rb:638:in `perform_delivery_smtp'
Here is my sample code
In mailer.rb
def mail_to_friend(recipient_mail, sender_mail, subjects, messages, host, port)
#host = host
#port = port
recipients recipient_mail
from "#{sender_mail}" #custom from address
subject "#{subjects}"
sent_on Time.now
body :message_body => messages, :host => host, :port => port
content_type "text/html"
end
I am using Rails 2.3.5 and Ruby 1.8.6.
PS: I am not using google smtp server(using own smtp server)
Thanks in Advance
The owner of the remote SMTP server banned you (or the guy you are impersonating), I guess because you were using their server to test weird stuff without asking for permission (or because what you are doing approximates what spammers do, and you triggered an automatic ban rule).