Can't send java mail to smtp host

I have this class inside my camunda environment(and i use this class like as service task inside camunda modeller):
public class SendMails implements JavaDelegate{

    String  text,from,password;
    Object jsonObject1=new JSONObject();
 public static void send( final String from, final String password,String to,String sub,String msg){  
     Properties props = new Properties();    
     props.put("", "");    
     props.put("mail.smtp.socketFactory.port", "465");    
     props.put("mail.smtp.auth", "true");    
     props.put("mail.smtp.port", "465");    
     //get Session   
     Session session = Session.getDefaultInstance(props,    
      new javax.mail.Authenticator() {    
      protected PasswordAuthentication getPasswordAuthentication() {    
      return new PasswordAuthentication(from,password);  
     //compose message    
     try {    
      MimeMessage message = new MimeMessage(session);    
      message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));    
      //send message  
      System.out.println("message sent successfully");    
     } catch (MessagingException e) {throw new RuntimeException(e);}    


    public void execute(DelegateExecution execution) throws Exception {

        text = execution.getVariable("selectedDocuments").toString();
        send("","xxxxx","","hello javatpoint","How r u?");  



<!-- -->
<!-- -->


but when i try to send message i got errors like this:

Caused by: com.sun.mail.util.MailConnectException: Couldn’t connect to host, port:, 465; timeout -1; nested exception is: Connection timed out: connect at com.sun.mail.smtp.SMTPTransport.openServer( at com.sun.mail.smtp.SMTPTransport.protocolConnect( at javax.mail.Service.connect( at javax.mail.Service.connect( at javax.mail.Service.connect( at javax.mail.Transport.send0( at javax.mail.Transport.send( at ge.psda.camunda.sendMails.SendMails.send( … 208 more

P.S i have enabled less secure up in my mail but this can’t helped me what should i change to be able to send mail?


Try with mail.sender set to the email account name rather than Camunda.

In addition;
Make sure your mail config is loaded by the app server, eg how do you install it.
Makes sure the jar files in the classpath are compatible with whats specified, eg mail, activation etc.
Also ensure there are no earlier versions of the library jars in places like the app server library folder…



hi @Webcyberrob
thank you for your response, i have changed my question content and logic in order to make it more clear, do you have any idea what should be the reason of connection errors?
Thank you in advance :smiley:


Do you have a firewall or similar either blocking the outbound connection or blocking the inbound response?



Yes i have firewall , is there any ability to configure this procedure without firewall?


Try adding this line to your props as the first line:
props.put(“mail.smtp.starttls.enable”, “true”);


@JARKKO_PARVIAINEN thank you for your response i have added this props.put(“mail.smtp.starttls.enable”, “true”); to my code, when i run this peace of code like java application apart from camunda environment i can send mail but in camunda environment i am stacukec at this point i mean neither i can send mail and nor get any exception