dcsimg
Problem Connecting to SMTP server thru Proxy
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sriram_v
Posted On:   Thursday, April 1, 2004 11:03 PM

Hi I have written a smtp client which i want to connect to smtp server through my proxy.I used the code like this:Two methods ive mentioned here: public void send () { Socket sock; try { sock=new Socket("ProxyName",ProxyPort); // Create the input stream inp = new BufferedReader(new InputStreamReader(sock.getInputStream() ) ); // Create the output stream out = new PrintStream( sock.getOutputStream() ); try { out.println("CONNECT mailservername:25 "); // Look for the initial e-mail salutation // this.dialog( null, "220" ); // Send HELO and await respons   More>>
			
Hi
I have written a smtp client which i want to connect to smtp

server through my proxy.I used the code like this:Two methods ive mentioned here:


public void send () {
Socket sock;
try {

sock=new Socket("ProxyName",ProxyPort);

// Create the input stream
inp = new BufferedReader(new InputStreamReader(sock.getInputStream() ) );

// Create the output stream
out = new PrintStream( sock.getOutputStream() );


try {

out.println("CONNECT mailservername:25
");

// Look for the initial e-mail salutation
// this.dialog( null, "220" );

// Send HELO and await response
this.dialog( "HELO Domainname
", "250" );

// Send the "MAIL FROM" and await response
String mailFrom = "MAIL FROM: <" + s_sender + ">
";
this.dialog( mailFrom, "250" );

// Send the "RCTP TO" and await response
String rcptTo = "RCPT TO: <" + s_recipient + ">
";
this.dialog( rcptTo, "250" );

// Send the DATA command
this.dialog( "DATA
", "354" );

// Send the e-mail source
String from = "From: " + s_sender + "
";
this.dialog( from, null );

// Send the e-mail destination
String recip = "To: " + s_recipient + "
";
this.dialog( recip, null );

// Send the subject
String subject = "Subject: " + s_subject + "
";
this.dialog( subject, null );

// Send the Content Type
String ct = "Content-Type: " + s_content_type + "
";
this.dialog( ct, null );

// Send the e-mail body
this.dialog( s_contents, null );

// Await e-mail receipt acknowledgment
this.dialog( "
.
", "250" );

// End the mail server dialog
this.dialog( "QUIT
", "221" );

// Close the client socket
sock.close();

} catch( MyException e ) {

System.out.println( e );
}



private void dialog( String command,String expected_response ) throws MyException {

// If a command is available, send it to the server
if ( command != null ) {

out.println(command);

}
// If a response is expected, get it and test it
// against the desired response.

if ( expected_response != null ) {

try {

// Get a line from the SMTP server through
// the socket
String line = inp.readLine();
System.out.println("The Command is "+command);
System.out.println("The ServerRe is :"+line);

// Check the status code
if (expected_response.equalsIgnoreCase(line.substring( 0,expected_response.length() ) ) ) {

return;

} else {

// Not the expected response, throw an exception
throw new MyException();

}

} catch( IOException e ) {
// Another error occurred, throw an exception
throw new MyException();

}

}

}


The Response from the server after the first command is

OUTPUT
The Command is HELO yahoo.com

The ServerRe is :HTTP/1.0 200 Connection established
smtpc$MyException
Press any key to continue . . .
------------------------------------------------------------------------------------
The Application terminatesSurprise is that i m getting HTTP response rather than a response from SMTP server.It shows whether im not connected to the remote server thru proxy ..Anyone pls guide me...thanks in advance
Regds
VR
   <<Less

Re: Problem Connecting to SMTP server thru Proxy

Posted By:   Christopher_Koenigsberg  
Posted On:   Friday, April 2, 2004 05:57 AM

Your proxy is an HTTP proxy. It doesn't talk SMTP.

About | Sitemap | Contact