Solved

Java sending SMTP commands on Data Stream

Posted on 2008-09-30
6
598 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Eclipse Neon and jdk 1.8.0 11 139
Java Message handling in Service Layer 3 58
Groovy:unable to resolve class error 2 70
arguments to jar 5 17
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This video teaches viewers about errors in exception handling.

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now