package test; import jakarta.mail.*; import jakarta.mail.internet.*; import java.util.Properties; public class GmailTest { public static void main(String[] args) throws Exception { Properties props = new Properties(); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "587"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.starttls.required", "true"); props.put("mail.smtp.ssl.enable", "false"); props.put("mail.smtp.ssl.protocols", "TLSv1.2"); props.put("mail.debug", "true"); Session session = Session.getInstance(props, new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication( "*****@gmail.com", "******" ); } }); Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress("*****@gmail.com@gmail.com")); msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("*****@gmail.com@gmail.com")); msg.setSubject("Test mail"); msg.setText("Hello from Jakarta Mail via Gmail 587 STARTTLS!"); Transport.send(msg); System.out.println("Message sent!"); } }