17

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.

12

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 google._domainkey.example.com.

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.

  • What if you're not in control of the DNS server? – Ishmael Oct 7 '13 at 14:56
  • 1
    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
4

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("example@gmail.com", "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:

transport.close();
0

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

settings = {
  address:        "smtp.gmail.com",
  port:           587,
  domain:         "mydomain.com",
  user_name:      "user@mydomain.com",
  password:       "password",
  authentication: "plain"
}

smtp_conn = Net::SMTP.new(settings[:address], settings[:port])
smtp_conn.enable_starttls_auto
smtp_conn = smtp_conn.start(settings[:domain],
                            settings[:user_name],
                            settings[:password],
                            settings[:authentication])
Mail.defaults do
  delivery_method :smtp_connection, { :connection => smtp_conn }
end

# send mails..
mail = Mail.new
mail.to('...')
# more mail stuff..
mail.deliver!

# after all mails are sent, end session
smtp_conn.finish
0

Using SMTP when you send bulk email it login with every single mail and then logout. Because of that googles blocks your connection. What worked for me is is to set SMTPKeepAlive to true.

  • 1
    It has already been suggested to not login for each mail. – RalfFriedl Jun 7 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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