Solved

Java sending SMTP commands on Data Stream

Posted on 2008-09-30
6
618 Views
Last Modified: 2013-11-05
Hello everyone and I have tried and searched and I am not sure why this one part of the code is not working. Okay here is what I have. I am using an Outbound data stream to connect to my excahnge servers SMTP port to send E-mail commands. Example of my code:

    os.writeBytes("EHLO"  + "\r\n");    
           os.writeBytes("RCPT TO: " + sEmail + "\r\n"); //Who is the message being sent Cc
                os.writeBytes("DATA" + "\r\n");//This is telling the SMTP service we are going to create the email to be sent.

                os.writeBytes("Testing e-mail " +  "\r\n"); // message body

                os.writeBytes(".\r\n");//Lets the SMTP PORT know you are down with the email DATA.
                os.writeBytes("QUIT" + "\r\n"); //SMTP Port knows you are not going to send any more information

Now my log shows that the responses are coming back okay. Example:

Server: 220 UHE2K3GW1.uhhs.com Microsoft ESMTP MAIL Service, Version: 6.0.3790.3959 ready at   Server: 250-UHE2K3GW1.uhhs.com Hello [10.51.181.53]
 Server: 250-TURN
 Server: 250-SIZE 20725760
 Server: 250-ETRN
 Server: 250-PIPELINING
 Server: 250-DSN
 Server: 250-ENHANCEDSTATUSCODES
 Server: 250-8bitmime
 Server: 250-BINARYMIME
Server: 250-CHUNKING
: Server: 250-VRFY
: Server: 250-TLS
 Server: 250-STARTTLS
 Server: 250-X-EXPS GSSAPI NTLM LOGIN
 Server: 250-X-EXPS=LOGIN
 Server: 250-AUTH GSSAPI NTLM LOGIN
 Server: 250-AUTH=LOGIN
 Server: 250-X-LINK2STATE
 Server: 250-XEXCH50
 Server: 250 OK
 Server: 250 2.1.0 TestFrom@email.com....Sender OK
 Server: 250 2.1.5 TestTo@email.org
: Server: 354 Start mail input; end with <CRLF>.<CRLF>

As you read above I am writing the SMTP command of DATA with my body and ending it with .+CRLF. However, the SMTP never respnds back. It is just sitting there and eventually timing out saying tha the client has not sent any data. Now I am running this program on a Sun Solaris 5.10 Unix OS. Is there something that is not working when I write these bits out with the .CRLF in this Unix version. I know this program worked on an old AIX Unix box and my commands work locally just no in this program. Thoughts..

0
Comment
Question by:Corey_819
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 9

Accepted Solution

by:
mbodewes earned 250 total points
ID: 22608836
What are you using to synchronize the stream? I mean, normally you are writing the command, reading back the response, writing the next command etc. etc. If this is all the code within the method, then there seems to be two streams that are handled separately. This might work, if the timing is not too far off. Running on a different (faster) machine though may make a difference.
0
 
LVL 1

Author Comment

by:Corey_819
ID: 22608930
Good point mbodewes and during my trouble shooting I was wondering how I would be able to trouble shoot the exact response after i write. Let me see what I can do with getting them snych.
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 22611329
I don't believe you need synchronization for one client. While I look into the code you have given, I could not
find anywhere you are reading the responses from the server?
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 1

Author Comment

by:Corey_819
ID: 22614412
Ajay, whoops sorry I am at the botto mof my code. Here it is:

 while ((responseLine = is.readLine()) != null) {
                     EGate.collabDebug("Server: " + responseLine);
                    if (responseLine.indexOf("Ok") != -1) {
                      break;
                    }
                }
However, the synchronization actually maybe an issue. The reason I say that is when I changed my code to read the response after each time I write a command out. One of my e-mails went through and was successful.
0
 
LVL 9

Expert Comment

by:mbodewes
ID: 22615094
Ajay-Singh: this is something I've personally experienced (with a small PERL script, but the idea is the same), not something purely theoretical. It's also something well documented (for these kind of PERL scripts).
0
 
LVL 1

Author Comment

by:Corey_819
ID: 22615619
Yeah you know what is funny is on our old hardware this was not a problem when we were on the AIX unix system and hardware. I guess the server must have been slow enough or maybe our SMTP service is slower. Thanks :)
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question