Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Automatically checking mails in SMTP with JavaMail...?  RSS feed

 
Ved Antani
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can we automatically check arrivals of new mails in an SMTP based mails like yahoo using JavaMail ? If yes, how ?

Please guide me.

-Ved
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes (though you'd use POP3, not SMTP, for that). As for how, the JavaMail tutorial on Sun's site has example code.
 
Ved Antani
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,

Thanks. I got your point, I am using the same code sample shipped with JavaMail installer. The problem is that I am behind a proxy, I have given the following proxy settings..

props.put( "proxySet", "true" );
props.put("http.proxyHost", "www.proxy.com");
props.put("http.proxyPort", "80");
//No username password for proxy is required.

store = session.getStore("pop3");
store.connect("smtp.mail.yahoo.com","username","password");

Here I get the following exception.

javax.mail.MessagingException: Connect failed;
nested exception is:
java.net.NoRouteToHostException: No route to host: connect
javax.mail.MessagingException: Not connected
at com.sun.mail.pop3.POP3Store.checkConnected(POP3Store.java:223)
at com.sun.mail.pop3.POP3Store.getFolder(POP3Store.java:205)
at monitor.main(monitor.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.intellij.rt.execution.application.AppMain.main(Unknown Source)

I dont understand this...please guide me.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SMTP and proxy servers can be awkward - since proxy servers tend only to be configured to support HTTP. You can either reconfigure your proxy to support SMTP, which is the easy way if you have the admin rights to do this, or if it supports SOCKS protocol you can redirect TCP socket connections to the proxy server. I can't quite remember how this is done (you'll have to check the docs) but its something like running your app with the param -DsocksProxy=proxyName. There's something in the JavaMail FAQs on Suns's site about this I think.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!