Solved

Java sending SMTP commands on Data Stream

Posted on 2008-09-30
6
595 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 1

Author Comment

by:Corey_819
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

762 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

10 Experts available now in Live!

Get 1:1 Help Now