• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unknown SMTP host for gmail

 
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi pals ,

is there anything wrong in this code , because i cant figure anything wrong in it and i'm getting this exception :





Here is the code:





any suggestions?
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check out this

https://coderanch.com/t/274576/java/java/send-mail-gmail-server
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This code is working, with the used properties set.

To enable debug when you try to send - just change "smtpSession.setDebug(false);" to "smtpSession.setDebug(true);"
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rene Larsen:
This code is working, with the used properties set.

To enable debug when you try to send - just change "smtpSession.setDebug(false);" to "smtpSession.setDebug(true);"



setProperty

public Object setProperty(String key,
String value)

Calls the Hashtable method put. Provided for parallelism with the getProperty method. Enforces use of strings for property keys and values. The value returned is the result of the Hashtable call to put.

link

i also tried it with setProperty(), still the exception the same...
 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please ignore the use of 'setProperty' and see which properties I have used instead!
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found this code on sun tutorials and i tried and it but still getting the same exception.
i think the gmail SMTP server is wrong , anyone got the right one?

here is the code :

 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried with the port number I have used??

What is printet when you enable debug??
 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And the code I have posted is working with Google mail - you can just use your own mail username and password
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rene Larsen:
And the code I have posted is working with Google mail - you can just use your own mail username and password



i tired your code with my information and still giving this exception
here it is :



i dont know what wrong
 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you able to ping 'smtp.gmail.com' from your machine??
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i tried ping smtp.gmail.com this was the reply
Ping request could not find host smtp.gmail.com. Please check the name and try again.
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rene , i just remembered that I'm behind a proxy do you think this may effect on me ?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like a network problem on your end. I can ping that host with no problem. Have you talked to the network admin?

Updated after reading the last post: Yes, a proxy would affect this. You need to configure the connection to go through the proxy.
[ September 08, 2008: Message edited by: Ulf Dittmer ]
 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sherif Shehab:
i tried ping smtp.gmail.com this was the reply
Ping request could not find host smtp.gmail.com. Please check the name and try again.



I don't know how you machine network is set up.

But...

Are you sitting on a school network?? - contact the network administrator.
Do you connect through VPN?? - try to connect without.

You can also try a 'traceroute smtp.gmail.com' then you will see where the lookup stops.
 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sherif Shehab:
Rene , i just remembered that I'm behind a proxy do you think this may effect on me ?



Yes
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok I'll try it from home and I'm sure there is no proxy there and tell you what happened
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rene Larsen:


Yes



Rene , it worked fine in home so this means that the proxy is spoiling it , do you got any idea to deal with javaMail behind proxy?
 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just did a google on "javamail proxy" and got this one as the first result: JavaMail send a mail through a Proxy Server..(answer) and with Gmail(SSL)

It seams to be easy to do - just add

to your existing Properties object.
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cool, so if is http proxy i guess it will be props.setProperty("httpProxyHost","PROXY_IP"); right ?

anyway thanks much for your help , and i'll try the proxy issue tomorrow then tell you what happened
 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, as I read it you need to use 'socksProxy*'

Normally, if you ask question like this. people like to answer you

Properties props = System.getProperties();
props.setProperty("proxySet","true");
props.setProperty("ProxyHost","192.168.155.1");
props.setProperty("ProxyPort","1080");



or set the HTTP proxy host and port

Properties props = System.getProperties();
props.setProperty("proxySet","true");
props.setProperty("http.proxyHost","192.168.155.1");
props.setProperty("http.proxyPort","808");



But above codes will not working with javamail.

well, what should you do,

here is the solution that you can send mail through a proxy server

Properties p = System.getProperties();
p.setProperty("proxySet","true");
p.setProperty("socksProxyHost","192.168.155.1");
p.setProperty("socksProxyPort","1080");



I have not tried to set up javamail with a proxy my self - so I don't know if it works. I think that there maybe can be an issue with logon to the proxy server - but I have not found how this is done.
 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found this link Networking Properties if you need to provide username and password to the proxy.


SOCKS protocol support settings

The SOCKS username and password are acquired in the following way. First, if the application has registered a java.net.Authenticator default instance, then this will be queried with the protocol set to the string "SOCKS5", and the prompt set to to the string "SOCKS authentication". If the authenticator does not return a username/password or if no authenticator is registered then the system checks for the user preferences "java.net.socks.username" and "java.net.socks.password". If these preferences do not exist, then the system property "user.name" is checked for a username. In this case, no password is supplied.

socksProxyHost
socksProxyPort (default: 1080)
Indicates the name of the SOCKS proxy server and the port number that will be used by the SOCKS protocol layer. If socksProxyHost is specified then all TCP sockets will use the SOCKS proxy server to establish a connection or accept one. The SOCKS proxy server can either be a SOCKS v4 or v5 server and it has to allow for unauthenticated connections.

 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rene Larsen:
No, as I read it you need to use 'socksProxy*'


I have not tried to set up javamail with a proxy my self - so I don't know if it works. I think that there maybe can be an issue with logon to the proxy server - but I have not found how this is done.



Rene , i noticed that the proxy usename and password are missing so what are the property to set them?
 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sherif Shehab:


Rene , i noticed that the proxy usename and password are missing so what are the property to set them?



As I wrote in my previous post

I have not tried to set up javamail with a proxy my self - so I don't know if it works. I think that there maybe can be an issue with logon to the proxy server - but I have not found how this is done.



I have postet a link where the username and password are defined - but again I have not tried to set up javamail with a proxy my self, so I don't know if it is working.
[ September 09, 2008: Message edited by: Rene Larsen ]
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the final answer for : "Does java mail can work behind proxy ?"

Check the answer here : Answer
so i think I'm stuck because i think my proxy http type
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This seems to be a internet connectivity issue, Have a look at this website post http://www.compiletimeerror.com/2013/03/java-mail-api-send-email-from-java-code.html comment. It has a solution.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This error occurs when you are not connected to the internet. Seems your codes are ok. Check you are connected to internet and also check your antivirus / firewall settings.
 
There is no greater crime than stealing somebody's best friend. I miss you tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic