Java sending SMTP commands on Data Stream
Posted on 2008-09-30
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-SIZE 20725760
: Server: 250-VRFY
: Server: 250-TLS
Server: 250-X-EXPS GSSAPI NTLM LOGIN
Server: 250-AUTH GSSAPI NTLM LOGIN
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..