0

Hi I'm using the following code to send email:

public static void sendEmail(String from, String to, String password) {
    Email email = new SimpleEmail();
    email.setHostName("smtp.googlemail.com");
    email.setSmtpPort(465);
    email.setAuthenticator(new DefaultAuthenticator(from, password));
    email.setSSLOnConnect(true);
    email.setSubject("Plain mail");
    email.setMsg("test");
    email.addTo(to);
    email.send();
}

Now, it works when I'm calling this function with my "normal" gmail address:

sendMail("me@gmail.com","friend@gmail.com", "my-password");

So the above works. But when I'm trying to migrate to Gmail for Business, and create an email address "me@mycompany.com" (which is hooked to Gmail), I get an authentication error:

sendMail("me@mycompany.com","friend@gmail.com", "my-new-password");

Gives me this error:

javax.mail.AuthenticationFailedException:
<https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsb...ZlTLN2wQG4> 
Please log in via your web browser and then try again.

I suspect I need to set something in my Google Apps console, but I'm not even sure where to start looking for the info.

Can anybody help? Thanks.

Scott Mayers
  • 437
  • 6
  • 18

1 Answers1

0

This answer is coming from a similar SO question here.

The issue is due to allowing less secure apps to access your account. Click the following link https://www.google.com/settings/security/lesssecureapps and disable security setting. For more information you can read this here.

Good luck!

Community
  • 1
  • 1
Andres
  • 671
  • 4
  • 9
  • Thanks! That did work, although in "Gmail for Business" this link doesn't work. One needs to go to https://admin.google.com/your-application-name/AdminHome#ServiceSettings/notab=1&service=securitysetting&subtab=lesssecureappsaccess , and of course, this is a bit scary setting. – Scott Mayers Dec 09 '15 at 15:38