i am getting this error.This error occurs when I send the confirmation code to the email of the registered user, but either succeeds or fails. javax.mail.MessagingException: Exception reading response; nested exception is: java.net.SocketTimeoutException: Read timed out at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2445) at com.sun.mail.smtp.SMTPTransport.ehlo(SMTPTransport.java:1684) at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:730) at javax.mail.Service.connect(Service.java:388) at javax.mail.Service.connect(Service.java:246) at javax.mail.Service.connect(Service.java:195) at javax.mail.Transport.send0(Transport.java:254) at javax.mail.Transport.send(Transport.java:124) at az.unibank.employee.mail.SendEmail.send(SendEmail.java:49) at az.unibank.employee.mail.SendEmail.lambda$sendAsync$0(SendEmail.java:13) at java.lang.Thread.run(Thread.java:748) Caused by: java.net.SocketTimeoutException: Read timed out at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) at java.net.SocketInputStream.read(SocketInputStream.java:171) at java.net.SocketInputStream.read(SocketInputStream.java:141) at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:126) at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) at java.io.BufferedInputStream.read(BufferedInputStream.java:265) at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:104) at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2425) ... 10 more public class SendEmail { public static void sendAsync(String toEmail, String text, String subject) { new Thread(() -> { send(toEmail, text, subject); }).start(); } public static void send(String toEmail, String text, String subject) { final String username = "anar.memmedov1501@gmail.com"; final String password = "sAlam12345"; Properties prop = new Properties(); prop.put("mail.smtp.host", "smtp.gmail.com"); prop.put("mail.smtp.port", "587"); prop.put("mail.smtp.auth", "true"); prop.put("mail.smtp.starttls.enable", "true"); Session session = Session.getInstance(prop, new javax.mail.Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(username)); message.setRecipients( Message.RecipientType.TO, InternetAddress.parse(toEmail) ); message.setSubject(subject); message.setText(text); Transport.send(message); } catch (MessagingException e) { e.printStackTrace(); } } } and this my send email code this problem occurs occasionally, but it wasn't like this before. I can't quite understand why. is there anyone,who help me?
I seriously can't handle this problem, I don't understand why.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)