• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 665
  • Last Modified:

Java sending SMTP commands on Data Stream

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 []
 Server: 250-TURN
 Server: 250-SIZE 20725760
 Server: 250-ETRN
 Server: 250-PIPELINING
 Server: 250-DSN
 Server: 250-8bitmime
 Server: 250-BINARYMIME
Server: 250-CHUNKING
: Server: 250-VRFY
: Server: 250-TLS
 Server: 250-STARTTLS
 Server: 250-X-EXPS=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..

  • 3
  • 2
1 Solution
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.
Corey_819Author Commented:
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.
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?
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Corey_819Author Commented:
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) {
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.
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).
Corey_819Author Commented:
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 :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now