Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Java sending SMTP commands on Data Stream

Posted on 2008-09-30
6
Medium Priority
?
630 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 1000 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

660 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