Is it possible to send an email from my Java application using a GMail account? I have configured my company mail server with Java app to send email, but that's not going to cut it when I distribute the application. Answers with any of using Hotmail, Yahoo or GMail are acceptable.
Java – How to send an email by Java application using GMail, Yahoo, or Hotmail
emailgmailjakarta-mailjavamail-server
Related Question
- Regex – How to validate an email address using a regular expression
- Java – How to create an executable JAR with dependencies using Maven
- Java – How to avoid Java code in JSP files, using JSP 2
- Html – set subject/content of email using mailto:
- Java – How to create a memory leak in Java
- Java – Error – trustAnchors parameter must be non-empty
- Android – Send Email Intent
Best Solution
First download the JavaMail API and make sure the relevant jar files are in your classpath.
Here's a full working example using GMail.
Naturally, you'll want to do more in the
catch
blocks than print the stack trace as I did in the example code above. (Remove thecatch
blocks to see which method calls from the JavaMail API throw exceptions so you can better see how to properly handle them.)Thanks to @jodonnel and everyone else who answered. I'm giving him a bounty because his answer led me about 95% of the way to a complete answer.