Skip to main content
deleted 20 characters in body
Source Link
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!"); } } 
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!"); } } 
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")); msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("*****@gmail.com")); msg.setSubject("Test mail"); msg.setText("Hello from Jakarta Mail via Gmail 587 STARTTLS!"); Transport.send(msg); System.out.println("Message sent!"); } } 
edited title
Link

When Facing issue with SMTP gmail while sending mail using jakarta email throwing jakarta.mail.MessagingException: Could not convert socket to TLS;tls

edited body
Source Link

Using belowthese dependencies jakarta.activation-2.0.1.jar jakarta.mail-2.0.2

Using below dependencies jakarta.activation-2.0.1.jar jakarta.mail-2.0.2

Using these dependencies jakarta.activation-2.0.1.jar jakarta.mail-2.0.2

added 4 characters in body
Source Link
Loading
edited tags
Link
Loading
edited tags
Link
Loading
added 3 characters in body
Source Link
Loading
added 78 characters in body
Source Link
Loading
deleted 2 characters in body
Source Link
Loading
added 32 characters in body
Source Link
Loading
Source Link
Loading