M
Manish Hatwalne
This is the code I am trying. It should send mail with the required message.
But it throws an exception instead on my machine.
try{
URL mail = new URL("mailto:"+MAIL_TO);
URLConnection conn = mail.openConnection();
conn.setDoInput(false);
conn.setDoOutput(true);
conn.connect();
PrintWriter mout = new PrintWriter(new
OutputStreamWriter(conn.getOutputStream()));
mout.println("From: "+MAIL_FROM);
mout.println("To: "+MAIL_TO);
mout.println("Subject: "+MAIL_SUBJECT);
mout.println();
mout.println(message);
mout.close();
}
catch (Exception e){
e.printStackTrace();
}
The exception thrown is -
java.net.UnknownHostException: mailhost
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:143)
at java.net.Socket.connect(Socket.java:425)
at java.net.Socket.connect(Socket.java:375)
at sun.net.NetworkClient.doConnect(NetworkClient.java:139)
at sun.net.NetworkClient.openServer(NetworkClient.java:118)
at sun.net.smtp.SmtpClient.openServer(SmtpClient.java:111)
at sun.net.smtp.SmtpClient.<init>(SmtpClient.java:156)
at sun.net.smtp.SmtpClient.<init>(SmtpClient.java:162)
at
sun.net.www.protocol.mailto.MailToURLConnection.connect(MailToURLConnection.
java:70)
What could be the problem?? The same code works on another machine with same
JDK configuration. So I think it might be a configuration problem.
TIA,
- Manish
But it throws an exception instead on my machine.
try{
URL mail = new URL("mailto:"+MAIL_TO);
URLConnection conn = mail.openConnection();
conn.setDoInput(false);
conn.setDoOutput(true);
conn.connect();
PrintWriter mout = new PrintWriter(new
OutputStreamWriter(conn.getOutputStream()));
mout.println("From: "+MAIL_FROM);
mout.println("To: "+MAIL_TO);
mout.println("Subject: "+MAIL_SUBJECT);
mout.println();
mout.println(message);
mout.close();
}
catch (Exception e){
e.printStackTrace();
}
The exception thrown is -
java.net.UnknownHostException: mailhost
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:143)
at java.net.Socket.connect(Socket.java:425)
at java.net.Socket.connect(Socket.java:375)
at sun.net.NetworkClient.doConnect(NetworkClient.java:139)
at sun.net.NetworkClient.openServer(NetworkClient.java:118)
at sun.net.smtp.SmtpClient.openServer(SmtpClient.java:111)
at sun.net.smtp.SmtpClient.<init>(SmtpClient.java:156)
at sun.net.smtp.SmtpClient.<init>(SmtpClient.java:162)
at
sun.net.www.protocol.mailto.MailToURLConnection.connect(MailToURLConnection.
java:70)
What could be the problem?? The same code works on another machine with same
JDK configuration. So I think it might be a configuration problem.
TIA,
- Manish