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)
Related
I just started to get error messages of "end of file reached error" from email sent inside the sidekiq worker from couple days ago.
The below code is config setting for action mailer.
config.app_domain = 'www.mydomain.com'
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = {host: config.app_domain }
config.action_mailer.smtp_settings = {
address: 'smtp.mailgun.org',
port: '587',
enable_starttls_auto: true,
user_name: 'postmaster#mydomain.com',
password: 'somepassword',
authentication: :plain,
domain: 'mydomain.com',
}
It's weird to see most of emails are properly sent, but only few emails are being reported. However I'm not at the position being able to ignore these issues in case of a potential hazardous ramification.
Please share any thoughts, any ideas how to ideally manage this error.
Best
In ruby, sockets are IO objects. An EOFError (End of File error) is raised when an operation on the IO object references the end of the file.
The remote email server is closing the socket unexpectedly. If you want to ignore this type of error, you'll need to write your own Worker to replace Sidekiq's built-in ActionMailer delay extension. If you want make it silent, then you can do something like
begin
# your code to send email here
rescue EOFError
# retry by calling the same worker again(if required)
end
Have an alert on time-series based delivery failure alerts which can be on percentage or count of emails not being delivered.
I am using a 3rd party library that sends emails using a HTTP based API.
Is it still possible for me to use ActionMailer to construct the emails and then somehow use ActionMailer to generate the resulting HTML/text for the email which I could then pass to my http email lib to send?
Absolutely. In fact, this is standard practice. You don't need to do anything special, just configure ActionMailer to use the 3rd party of your choice. Here's an example from my production.rb file, using Mailgun:
Rails.application.configure do
# other config stuff goes here...
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { host: 'your_domain.com' }
config.action_mailer.smtp_settings = {
authentication: :plain,
address: 'smtp.mailgun.org',
port: 587,
domain: Rails.application.secrets[:mailgun_domain],
user_name: Rails.application.secrets[:mailgun_username],
password: Rails.application.secrets[:mailgun_password]
}
end
Then in your Rails.application.secrets file, you put the info specific to your account.
I'm trying to send emails from my rails application using GMail's smtp server.
The emails I send appear like sent from my own gmail address, while I would like them to be coming from info#myapp.com.
I've configured the thing using the three ways authentication, and my app has got its unique password. Here's my production.rb
config.action_mailer.default_url_options = {
host: 'my ip',
protocol: 'https'
}
config.action_mailer.delivery_method = :smtp
config.action_mailer.asset_host = "https://my ip"
and here's my initializers/smtp.rb
MyApp::Application.configure do
config.action_mailer.smtp_settings = {
enable_starttls_auto: "true",
address: "smtp.gmail.com",
port: "587",
domain: "mydomain.com",
authentication: :plain,
user_name: 'myusername#gmail.com',
password: 'mypassword'
}
end
Is it possible? How could I do that?
I figured my solution,
I have two mailer controllers in my application, one is from devise and sends mail for user registration related stuff, and the other sends emails to me in the from the contacts page.
First let's see the configuration in google. Google allows to send emails with a different sender email, but it requires that you own the mail address, so there's a procedure to follow to verify your email address on google. It's listed here
I used that procedure to validate my email address: no_reply#myapp.com which is the one I want my emails to appear to be from
Once gmail has verified that you own the sender email address I configured devise, I changed in the config/initializers/devise.rb adding the line:
config.mailer_sender = "'myapp_noreply' <no_reply#myapp.com>"
Second I went to configure my app/mailers/notifications_mailer, by adding the line:
default :from => "no_reply#myapp.com"
I tested everything and it worked fine. If I check in the email's headers I can still see my gmail account appearing. These look like this:
Return-Path: <mygmail#gmail.com>
Received: from myapp.com ([2231:7120::f12c:912f:f12e:5123])
by mx.google.com with ESMTPSA id gn1sm32851027wib.14.2014.04.01.05.20.26
for <info#casamaroma.it>
(version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
Tue, 01 Apr 2014 05:20:26 -0700 (PDT)
Sender: Giulio <mygmail#gmail.com>
Date: Tue, 01 Apr 2014 12:20:25 +0000
From: 'myapp_noreply' <no_reply#myapp.com>
Reply-To: 'myapp_noreply' <no_reply#myapp.com>
To: destination#email.com
Message-ID: <533aaf09c5237_2b0b123fe8c3341a#server.mail>
Subject: Confirmation instructions
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Because the from field is set to the one I need, I don't care too much for the rest.
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'
}
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.