aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Unknown SMTP host for gmail Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Unknown SMTP host for gmail" Watch "Unknown SMTP host for gmail" New topic
Author

Unknown SMTP host for gmail

Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

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?


Thanks,
Sherif
Adinath Shirsath
Ranch Hand

Joined: Dec 04, 2007
Posts: 35
check out this

http://www.coderanch.com/t/274576/java/java/send-mail-gmail-server
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

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);"


Regards, Rene Larsen
Dropbox Invite
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

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

Joined: Oct 12, 2001
Posts: 1179

Please ignore the use of 'setProperty' and see which properties I have used instead!
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

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

Joined: Oct 12, 2001
Posts: 1179

Have you tried with the port number I have used??

What is printet when you enable debug??
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

And the code I have posted is working with Google mail - you can just use your own mail username and password
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

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

Joined: Oct 12, 2001
Posts: 1179

Are you able to ping 'smtp.gmail.com' from your machine??
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

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.
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

Rene , i just remembered that I'm behind a proxy do you think this may effect on me ?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42908
    
  69
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

Joined: Oct 12, 2001
Posts: 1179

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

Joined: Oct 12, 2001
Posts: 1179

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


Yes
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

ok I'll try it from home and I'm sure there is no proxy there and tell you what happened
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

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

Joined: Oct 12, 2001
Posts: 1179

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.
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

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

Joined: Oct 12, 2001
Posts: 1179

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

Joined: Oct 12, 2001
Posts: 1179

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.
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

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

Joined: Oct 12, 2001
Posts: 1179

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 ]
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

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
Ragavan Raju
Greenhorn

Joined: Dec 28, 2012
Posts: 10
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.
Jithin Johny George
Greenhorn

Joined: Oct 15, 2013
Posts: 1
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unknown SMTP host for gmail