This is the code of the class Mail (there are a main inside but for the simple reason that in this way it seem to be simple to solve this problem):
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;
public class Mail {
public static void main(String [] args) {
// Recipient's email ID needs to be mentioned.
String to = "abcd@gmail.com";
// Sender's email ID needs to be mentioned
String from = "mail";
String psw = "password";
// Assuming you are sending email from localhost
String host = "localhost";
//