except this I used other hosts also but it is giving same error with host name , But another thing is that same application is working fine from another machine in my office It is not giving exceptions , we are behind firewall ,I think due to this problem is occuring any Idea Please help Thanks , Bibhishan
Jared Krull
Ranch Hand
Joined: Sep 28, 2001
Posts: 32
posted
0
If you are behind a firewall there is a good reason. Part of the reason for them is to block un-recognised programs contacting the net. If you have this problem you should discuss it with your System Administrator and see if he/she will allow you access. Firewalls arent easy to bypass - thats the whole point I'm afraid.
C programmer gone astray
Bibhishan Karadkar
Greenhorn
Joined: Oct 03, 2001
Posts: 10
posted
0
Thanks for reply but I didnt' get what is problem actualt ,beca on another machine in my domain this application is working fine means sending mails but problem with my machine please let me know what will be the reasons behind this I am Using JavaMail1.2 & jaf-1.0.1 I am sending my code to U import javax.servlet.http.*; import java.io.*; import java.util.*; import javax.servlet.*; import javax.mail.*; import javax.mail.event.*; import javax.mail.internet.*; import javax.activation.*; //import javax.mail.smtp; public class MailClient extends HttpServlet { final String mailHost="202.9.128.101"; //final String mailHost="mail.ip.eth.net"; String source,dest,sub,content,fileName,fileStr="",str; File file; FileDataSource fileSource; PrintWriter out; public void init(ServletConfig config)throws ServletException { super.init(config); } public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException{ try { res.setContentType("text/html"); out = res.getWriter(); dest=req.getParameter("to"); source=req.getParameter("from"); sub=req.getParameter("sub"); content=req.getParameter("content"); fileName=req.getParameter("fileNm"); file = new File(fileName); Properties prop = System.getProperties(); prop.put("mail.smtp.host",mailHost); Session session = Session.getDefaultInstance(prop, null); //Session session = Session.getInstance(prop, null); InternetAddress[] address= InternetAddress.parse(dest);
MimeMessage msg = new MimeMessage(session); msg.addHeader("X-Priority", "1"); msg.setRecipients(Message.RecipientType.TO,address); msg.setFrom(new InternetAddress(source)); msg.setSubject(sub); if(file.exists()) { MimeBodyPart body = new MimeBodyPart(); body.setText(content); MimeBodyPart attachment = new MimeBodyPart(); fileSource = new FileDataSource(file); attachment.setDataHandler(new DataHandler(fileSource)); attachment.setFileName(fileSource.getName()); Multipart part = new MimeMultipart(); part.addBodyPart(body); part.addBodyPart(attachment); msg.setContent(part); } else { msg.setText(content); } Transport.send(msg); out.println("Mail send successfully"); } catch(Exception e) { out.println(e.toString()); } } } Exception is 453dce javax.mail.SendFailedException: Sending failed; nested exception is: javax.mail.MessagingException: Could not connect to SMTP host: 202.9.128.101, port: 25; nested exception is: java.net.NoRouteToHostException: Host unreachable: no further information Please Help me out Please correct me If I am wrong Tahnks