1

We are using the following snippet of code to send an email from java

    javaMailSenderImpl.setHost("somehost");
    javaMailSenderImpl.setPort(25);

    javaMailSenderImpl.testConnection();

    message = new SimpleMailMessage(); 

    message.setFrom("sender@abc.com");
    message.setTo("receiver@abc.com");
    message.setText("Hello world!!");

    System.out.println("************ before" + LocalTime.now());
    javaMailSenderImpl.send(message);
    System.out.println("************ after" + LocalTime.now());

JavaMailSenderImpl.send method takes about 6 seconds to execute, is there a way to reduce this time?

venkat g
  • 421
  • 1
  • 6
  • 20
  • Try with a different host, maybe the mail provider is slow. – wdc May 29 '18 at 12:22
  • How [slow is the DNS lookup](https://stackoverflow.com/questions/44435457/mimemessage-savechanges-is-really-slow/44438011#44438011)? – jmehrens May 30 '18 at 15:31

1 Answers1

1

Yeah, You are right JavaMailSender was bit slow. So you can use thread to avoid timing issue. Note- Its not a solution, It's just my suggestion. You can create new thread like this.

 new Thread(() -> {
            try {
              //do your business here
              ..............
            } catch (IOException | MessagingException e) {
                e.printStackTrace();
            }
        }).start();
Jay
  • 199
  • 1
  • 14