You can send email by sending a series of text commands and data to the mailserver. All JavaMail is doing there is providing convenient methods to package things up and transmit them properly*. So yes, any recent Java implementation of JavaMail can send email to mail.google.com.
On the other hand, gmail's authentication and authorization protocols have been quirky lately, so I can't provide a cookbook solution off my head. Last time I had to deal with it I was setting up an email client on a tablet device and there was much swearing.
* Well, that and provide an API to run the process in reverse allowing for things like mailboxes.
Sources may include data from the Fakebook Research Foundation with support from Gargle University
As I've seen so many bad or even worse examples ... and some just plain wrong ... I can only imagine the lines that led to this Exception.
Recent Java versions have the required root certificates in their certificate store. On most Linux systems its a symlink to the mozilla-ca package instead of using its own root ca store. And as I don'T think someone at Google screwed up it's most likely the (probably bad) code.
Just post it ... I guess it suffers from using SMTP with TCP/465 - which is SMTPS.
For what it's worth, I added code tags around your code so that it's more readable. However: there are some typing errors which will prevent it from compiling, and you have misspelled the names of the properties. Besides that it would be helpful if you explained how that code deals with the problem which the OP described.
you can try in this way:
check smtp ports and packages
sample java program to send mail:
I've requested a fix for your missing code-tags, but there's quite a few lines "not the way it should be done" ... and a few others are just wrong.
1) Aside from the way you authenticate, which can be done better, it wouldn't work without first setting up an application password for access your gmail account this way. By default, google only accept OAuth2 tokens, if one want to use regular passwords it has to be specified upfront in gmail settings.
2) You have missed the line where you add the actual message. This would result in gmail reject this message as spam. Yes, simple text/plain messages are ok, but only if they have meaningful subject and message body.
3) Your properites would fail as they're Uppercase - Java is case sensitive. Mail.something != mail.something.
4) I don'T really know why this lib was designed this way, but the static Transport.send() method is rather bad style. Some lines how to use this lib in a better way:
Also I notice that the code you posted ignores the "msg" parameter, i.e. it doesn't include it in the mail message that would be sent. And another thing, after correcting the spelling of the "Authenticator" class name:
The JavaMail FAQ wrote:There's really nothing wrong with using an Authenticator, it's just unnecessarily complex. A more straightforward approach is to call the connect method that takes a username and password when connecting to a Store. When sending a message, use the static Transport.send method that takes a username and password.
We appreciate all submissions here, but it would be helpful if you corrected the problems with this one. After all, copying and pasting code from the web and finding it doesn't work can be very annoying.
Paul Clapham wrote:After all, copying and pasting code from the web and finding it doesn't work can be very annoying.
Issue with JavaMail in particular: About 99% of codes found on the net are only the bad style.
As said: I don't really get it why this lib was designed in such a bad style, but as its earliest versions date back to the 90s I guess it's the same with many such old libs: It suffers from Javas backwars ideology and would benefit from a major re-write.
May a true 2.0 version would be better today than a 1.17.