Average time to send 1 email (Heroku Rails 3 ActionMailer > Google Apps via SMTP)

I'm averaging about 2000ms per email. Is this normal? Can you give me some examples of times from your apps? The emails get delivered fine. I know I should probably be using DelayedJob or an SMTP relay like SendGrid, but I'm guessing its way too long and there's an underlying problem.

2012-06-13T21:28:55+00:00 app web.1 - - Sent mail to ... (7856ms)
2012-06-13T21:28:57+00:00 app web.1 - - Sent mail to ... (2003ms)
2012-06-13T22:24:42+00:00 app web.1 - - Sent mail to ... (3094ms)
2012-06-13T22:24:43+00:00 app web.1 - - Sent mail to ... (1722ms)
2012-06-14T02:20:37+00:00 app web.1 - - Sent mail to ... (5932ms)
2012-06-14T02:22:16+00:00 app web.1 - - Sent mail to ... (1830ms)
2012-06-14T02:22:18+00:00 app web.1 - - Sent mail to ... (1740ms)

If not, how do I go about debugging whats taking so long?

(btw logentries rocked for collecting this data)

My SMTP settings for posterity:

ActionMailer::Base.smtp_settings = {
  :address => "smtp.gmail.com",
  :port => 587,
  :domain => "example.com",
  :authentication => "plain",
  :user_name => "mail@example.com",
  :password => "...",
  :enable_starttls_auto => true 
}

Answers


No, this is average. I have an app that I have run on powerful servers, my own machine, and even a simple low end server, and they usually always ran about the same time to send it. It has to do with the authentication when talking to Google or who ever you are sending it through.

My app sends the email as soon as the user hits the email button on my screen, it then take a second or two for the alert to pop up on screen letting me know it was successfully sent. I am using a Google Apps Gmail account that I have associated with my business with the same kind information listed in the ActionMailer::Base.smtp_settings in my Rails Project as you do.

The reason is usually because it is connecting to Google, authenticating it and letting google send it off.

You could technically could use sendmail on your own server, if using Linux or Mac. Sendmail works faster because of the fact that it is sending it from the server itself, not connecting to google and then authenticating.

I have done this for client machines when sending huge bulk emails out, like news letters and such. The problem with this approach is that the header of the email doesn't have any authentication from a real mail server like Gmail, Hotmail, etc proving that the person who sent it actually sent it from a google/hotmail/etc server and can sometimes be seen as spam since its not truly authentic. There are plenty of guides on how to do it, like in this one that I just found:

http://raflabs.com/blogs/silence-is-foo/2011/02/07/configuring-rails-3s-actionmailer-work-sendmail-debian/

There are many others that you can use, it just depends on your style of working.

Be careful though if you go this route, your mail may be seen as spam. If the clients know they are going to be getting it though, it will usually go through just fine though.

If you still want to send mail using the method you are currently using, I would recommend having the email be handled by a queue in the background, that way, it is faster and doesn't cause any delay to the user when working with your app.

I hope that helps and answers your question.


Need Your Help

Error Downloading .apk from Asp.net website using android phone browser

c# android asp.net .net apk

In my .aspx page, I have download button which onclick download the .apk file.