Unknown SMTP host: smtp.gmail.com;

1,992 views
Skip to first unread message

sharmarock0110

unread,
May 29, 2018, 6:46:10 AM5/29/18
to Selenium Experts
I am trying to send email using my gmail id in my corporate/office network using  javamail API but getting below mentioned error:

Please help

javax.mail.MessagingException: Unknown SMTP host: smtp.gmail.com;
  nested exception is:
java.net.UnknownHostException: smtp.gmail.com
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1959)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
at javax.mail.Service.connect(Service.java:317)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at testinglatest.MonitoringMail.sendMail(MonitoringMail.java:51)
at testinglatest.TestMail.main(TestMail.java:14)

Deepak Thayat

unread,
May 29, 2018, 7:34:54 AM5/29/18
to seleniu...@googlegroups.com

Change the port number  to 465 if you passing value true to ssl certs in your code else try 25 with false.

--
You received this message because you are subscribed to the Google Groups "Selenium Experts" group.
Visit this group at https://groups.google.com/group/seleniumexperts.

sharmarock0110

unread,
May 29, 2018, 7:42:56 AM5/29/18
to Selenium Experts

i am using below mentioned code :

public void sendMail(String mailServer, String from, String[] to, String subject, String messageBody, String attachmentPath, String attachmentName) throws MessagingException, AddressException
{
boolean debug = false;
Properties props = new Properties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.EnableSSL.enable","true");
props.put("mail.smtp.auth", "true");

props.put("mail.smtp.host", mailServer); 
props.put("mail.debug", "true");
     props.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");   
     props.setProperty("mail.smtp.socketFactory.fallback", "false");   
     props.setProperty("mail.smtp.port", "465");   
     props.setProperty("mail.smtp.socketFactory.port", "465"); 

  Authenticator auth = new SMTPAuthenticator();
    Session session = Session.getDefaultInstance(props, auth);

    session.setDebug(debug);

tried with 25 as well it didn't worked.

selenium trainer

unread,
May 29, 2018, 7:44:30 AM5/29/18
to seleniu...@googlegroups.com
Your office firewall is actually blocking it, try the same code through your mobile network or home network and let me know if it works

sharmarock0110

unread,
May 30, 2018, 7:28:00 AM5/30/18
to Selenium Experts
Thanks, it started working after i changed the Internet network and used my personal one.
Reply all
Reply to author
Forward
0 new messages