• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Javamail and the Google API

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to send emails from my Java app. I can send them from my own domain using the JavaX-mail library but I want to send them so that they come from my GMail account. I have looked at the Google documentation regarding OAuth2 authentication and tried to follow it without success, it seems disjointed and doesn't have a clear step-by-step tutorial. Has anyone created one? Are there any straight forward tutorials?
 
Saloon Keeper
Posts: 28319
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not as easy as it used to be since Google added extra constraints on clients. I had to set up some IPV6 stuff in my DNS, for one.

I have a client set up to address port 465 at smtp.gmail.com using TLS.  That used to be enough, but as I said, I've had to adjust things since Google tightened up authentication and I haven't checked to see if I've got it all working. Login was via userid/password over TLS, not OAUTH, though.
 
Neil Barton
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tim, no I use that system for everything else but it no longer works with GMail :-(
 
Saloon Keeper
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you need or want to use OAuth2? If not, https://www.google.com/settings/security/lesssecureapps may be an option.
 
Neil Barton
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tim, unfortunately less secure apps has been deprecated and I can't use it any more. OAuth2 seems to be the only option. It is incredibly complicated though and I cannot find a simple straight forward, up to date, guide. The guides either refer to things that don't exist any more or simply get so complicated I end up going in cricles!
 
Tim Holloway
Saloon Keeper
Posts: 28319
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I find it unlikely that OAUTH2 is the only option, as its protocols aren't likely to play well with automated setups.

However to make up for the "less secure apps" deprecation, you might need to ensure that your DNS can vouch for you to google, as I mentioned earlier (having to add some IPV6 stuff to my DNS).

Check this out. It may help:

https://www.gmass.co/blog/gmail-smtp/
 
Neil Barton
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're right, OAuth2 is basically unusable (at least by me!). I followed your link and got to the point where it says find "App passwords" in my Google A/c. It's not their. There is the similar "Your connections to 3rd Party Apps" but it doesn't help as I can't seem to add a new one!
Google makes this really difficult!
 
Neil Barton
Ranch Hand
Posts: 152
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh wow! Wait! I searched for google app password and it came up with the app passwords screen. I set it up and guess what, it worked! Whoopee! Thanks Tim!
 
Ranch Hand
Posts: 342
1
Mac Eclipse IDE Safari
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm glad it's not just me who has been facing this problem. I write java applications which run as a service using a wrapper. They have not user interface, web component etc but do need to send emails. Recently Microsoft Hotmail/Outlook deprecated SMTP and I was looking at OAUTH2 but decided instead to send emails using my Apple account. I got the impression that apart from being inherently complicated to code, it also seems like it's not consistent, with Microsoft doing it slightly different than google and urrrggggggh - what a mess.

I was wondering if someone could write a program which could accept SMTP emails from a client but forward them on using AUTH2 authentication - like a proxy to help out legacy apps.

Dave
 
We cannot change unless we survive, but we will not survive unless we change. Evolving tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic