while I am trying to send email through Jenkins I am getting the issue.
javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
I think it's more a firewall issue :(
Can you try to launch this command on your Jenkins machine?
telnet your.smtp.server.com 25
If the test is successful, you should receive a message like that:
Trying XXX.XXX.XXX.XXX... Connected to your.smtp.server.com. Escape character is '^]'. 220 your.smtp.server.com ESMTP Postfix
If you don't receive this message, try to open the port 25 on your Jenkins machine.