Win a copy of Head First Android this week in the Android forum!

Khalid Gul

Greenhorn
+ Follow
since Apr 10, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Khalid Gul

Hi Guys
I am trying to get inputstream from a FTP Link using URL, URLConnection with the following code.

public int FTPCat(String hurl) {
try {
url = new URL(hurl);
br = new BufferedReader(new InputStreamReader(url.openStream()));
System.out.println( "******* DONE *******");
}
}
when I connect to it from the client on our network, it works fine. But I try to it from the server of the network it give me the folloing Exception.

java.net.SocketException: Connection reset by peer: JVM_recv in socket input stream read
at java.net.SocketInputStream.socketRead(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:86)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:186)
at java.io.BufferedInputStream.read(BufferedInputStream.java:204)
at sun.net.TransferProtocolClient.readServerResponse(TransferProtocolClient.java:52)
at sun.net.ftp.FtpClient.readReply(FtpClient.java:172)
at sun.net.ftp.FtpClient.issueCommand(FtpClient.java:161)
at sun.net.ftp.FtpClient.openDataConnection(FtpClient.java:218)
at sun.net.ftp.FtpClient.get(FtpClient.java:315)
at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnection.java:109)
at java.net.URL.openStream(URL.java:798)

I thought it is because of either any firewall or presence of two network cards on the server which blocks the connection. I have to run this code on server. So plz give me solution because I'm struggling for 2 weeks. Any help will be greatly appreciated.

Khalid
Karachi
Hi There again ,
we have a problem in displaying an image on other Email Account
when we send an email with an image from our own Email Application ,
Email Body opens successfully but image is not being displayed.



The class of Email which we have written for sending Email is written below;

//---------------start of class-------

package HandlerBeans.Email;

import javax.mail.*;
import javax.mail.Session;
import javax.mail.internet.*;
import java.util.*;
import javax.activation.*;

public class EmailHandler
{
public EmailHandler() { }//constructor

// public static boolean sendEmail(String from,String to,String subject,String

body,String FilePath)


public boolean sendEmail(String from,String to,String subject,String body,String

FilePath)
{
boolean debug= false;
String host = "smtp.multi.net.pk";
String filename = FilePath;
String msgText1 = body ;
// create some properties and get the default Session
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
Session session1 = Session.getDefaultInstance(props, null);
session1.setDebug(debug);
try {
// create a message
MimeMessage msg = new MimeMessage(session1);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = InternetAddress.parse(to);
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(msgText1);
// create the Multipart and its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
if(!filename.equals(""))
{
String fname = filename;
MimeBodyPart mbp2 = new MimeBodyPart();
// attach the file to the message
FileDataSource fds = new FileDataSource(fname);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());
mp.addBodyPart(mbp2);
}
// add the Multipart to the message
msg.setContent(mp);

// set the Date: header
msg.setSentDate(new java.util.Date());

// send the message
Transport.send(msg);

}
catch (MessagingException mex) {

mex.printStackTrace();
Exception ex = null;
if ((ex = mex.getNextException()) != null)
{
ex.printStackTrace();
}
return false;
}

return true;
}


}

// ---------------------- end of class -------------------


JSP code is written below
where we are calling the method
sendEmail(String from,String to,String subject,String body,String FilePath) for

sending Email


//--------------- JSP Code start--------------------

<%@ page language="java" import="com.jspsmart.upload.*"%>
<%@ page import="java.sql.*,java.util.*,java.io.*"%>

<jsp:useBean id="emailhandlerBean" scope="page"

class="HandlerBeans.Email.EmailHandler"/>

<%

String from="david@lonestarasp.com";
String to="kamran@hotmail.com";
String subject="Qurey About Email Image";

String body= "'<html><head></head><body><table>
<tr><td><strong> From LoneStarASp.Inc </strong ></tr></td></table>
<img src=http://www.mysite.com/image/image1.gif > </body></html>'" ;

String FilePath=null; //it means no file is attached

// email is going to send here

emailhandlerBean.sendEmail( from , to , subject , body , FilePath) ;

%>

//-------------------- jsp code end --------------



Can someone pleaseeeee tell us what are we doing wrong here, we would be very gratefull.

Thanks a million.

K.Gul
17 years ago
Hi There again ,
we have a problem in displaying an image on other Email Account
when we send an email with an image from our own Email Application ,
Email Body opens successfully but image is not being displayed.



The class of Email which we have written for sending Email is written below;

//---------------start of class-------

package HandlerBeans.Email;

import javax.mail.*;
import javax.mail.Session;
import javax.mail.internet.*;
import java.util.*;
import javax.activation.*;

public class EmailHandler
{
public EmailHandler() { }//constructor

// public static boolean sendEmail(String from,String to,String subject,String body,String FilePath)


public boolean sendEmail(String from,String to,String subject,String body,String FilePath)
{
boolean debug= false;
String host = "smtp.multi.net.pk";
String filename = FilePath;
String msgText1 = body ;
// create some properties and get the default Session
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
Session session1 = Session.getDefaultInstance(props, null);
session1.setDebug(debug);
try {
// create a message
MimeMessage msg = new MimeMessage(session1);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = InternetAddress.parse(to);
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(msgText1);
// create the Multipart and its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
if(!filename.equals(""))
{
String fname = filename;
MimeBodyPart mbp2 = new MimeBodyPart();
// attach the file to the message
FileDataSource fds = new FileDataSource(fname);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());
mp.addBodyPart(mbp2);
}
// add the Multipart to the message
msg.setContent(mp);

// set the Date: header
msg.setSentDate(new java.util.Date());

// send the message
Transport.send(msg);

}
catch (MessagingException mex) {

mex.printStackTrace();
Exception ex = null;
if ((ex = mex.getNextException()) != null)
{
ex.printStackTrace();
}
return false;
}

return true;
}


}

// ---------------------- end of class -------------------


JSP code is written below
where we are calling the method
sendEmail(String from,String to,String subject,String body,String FilePath) for sending Email


//--------------- JSP Code start--------------------

<%@ page language="java" import="com.jspsmart.upload.*"%>
<%@ page import="java.sql.*,java.util.*,java.io.*"%>

<jsp:useBean id="emailhandlerBean" scope="page" class="HandlerBeans.Email.EmailHandler"/>

<%

String from="david@lonestarasp.com";
String to="kamran@hotmail.com";
String subject="Qurey About Email Image";

String body= "'<html><head></head><body><table>
<tr><td><strong> From LoneStarASp.Inc </strong ></tr></td></table>
<img src=http://www.mysite.com/image/image1.gif > </body></html>'" ;

String FilePath=null; //it means no file is attached

// email is going to send here

emailhandlerBean.sendEmail( from , to , subject , body , FilePath) ;

%>

//-------------------- jsp code end --------------



Can someone pleaseeeee tell us what are we doing wrong here, we would be very gratefull. Thanks a million.

K.Gul
17 years ago
JSP
Hi There, we have a problem in displaying an image on other Email Account
when we send an email with an image from our own Email Application ,
Email Body opens successfully but image is not being displayed.

The content of the body which i am sending is written below;

String body= "'<html><head></head><body><table>
<tr><td><strong> From LoneStarASp.Inc </strong ></tr></td></table>
<img src="http://www.mysite.com/image/image1.gif> </body></html>'" ;


Can someone pleaseeeee tell us what are we doing wrong here, we would be very gratefull. Thanks a million.

K.Gul
17 years ago
i am developing web application using jsp with Appache Tomcat server ,
i am facing problem in transfering data from one web page of our system to web page of another web application having

different different URL . if anyone knows about such problem then please guide me to tackle such problem.
I will be very thankfull to him.
17 years ago