Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I discovered that while it was possible to use Gmail/Google Apps as an SMTP server for scripted use, if too many emails were sent I started getting error messages:

SMTP Error: 454 4.7.0 Too many login attempts, please try again later.

Usually if I waited an hour or two I could send out another 100 emails or so, but I would soon run into the same error message again.

share|improve this question
up vote 7 down vote accepted

I discovered that the problem was that although we had SPF records set up for our domains, we did not have a DKIM record associated with our domain. In order to add a DKIM record in Google Apps, you need to do the following:

  • Go to the Admin Console
  • Click on "Google Apps"
  • Click on "Gmail"
  • Scroll down until you see "Authenticate Email" and click that
  • Select the domain you wish to add DKIM to
  • When it asks what prefix you want to use, simply use the default of 'google'

You will then see a TXT record in two parts, one piece has the domain and the other has the actual TXT record. You need to go into your DNS settings on your server for your domain and add this record. If your DNS control panel does not allow you to add the domain of google._domainkey, simply make the domain fully qualified like

After you do this, give the DNS record a little bit of time to propagate and then click "Start Authentication" in the Google Apps admin panel. If you see a green checkmark, you've done it, and email should start flowing through the SMTP server once again.

share|improve this answer
What if you're not in control of the DNS server? – Ishmael Oct 7 '13 at 14:56
Thanks dude! You saved my life <3 – marverix Oct 18 '13 at 16:02
A lifesaver. It appears that gmail will check the authoritative servers for the TXT record, so you should not have to wait for full DNS propogation--for most changes made these days through a DNS zone file manager, you will not have to wait more than a few seconds for the change to take effect. – J.T. Taylor May 4 '15 at 15:43

You must not authenticate for each email you should send.

At the beginning of the process:

Session session = loadSession();
Transport transport = session.getTransport("smtp");
transport.connect("", "password");

After, use the transport object for send each mail without start session:

transport.sendMessage(message, message.getAllRecipients());

After you send all emails, you should close the connection:

share|improve this answer

solution from @victorpacheco3107 worked for me, this what I did in ruby:

settings = {
  address:        "",
  port:           587,
  domain:         "",
  user_name:      "",
  password:       "password",
  authentication: "plain"

smtp_conn =[:address], settings[:port])
smtp_conn = smtp_conn.start(settings[:domain],
Mail.defaults do
  delivery_method :smtp_connection, { :connection => smtp_conn }

# send mails..
mail ='...')
# more mail stuff..

# after all mails are sent, end session
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.