Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

Socket problem

Thread view: 
Loek Raemakers - 09 Mar 2006 20:41 GMT
Mail-problem.

I want tot add a mailfunction to my java-application. The  application runs on
an local nework.Students use it to sign up; the application places them in
groupes, and on lists/ waitinglists. I want to send them by mail these lists.
I use a Socket connection, from the local network to the mailserver.

Socket mysocket = new Socket("" + ipaddress,25,true);
I use the IP address and not the server name, supposing that there is no DNS.

public void MailerGroeps()
{  
   // Verstuurt de mail aan de hele groep;
   // via een lus krijgen allen een mail.
   // Let op wat precies in die lus staat.
   // De body tekst bestaat uit: vast deel + getypt deel.

   String recepient = "";
          try
     {
       Socket outgoing = new Socket(host,portnum,true);
       PrintStream ps = new PrintStream(outgoing.getOutputStream());
      
           ps.println("HELO " + host);// "Polite people say helo"
       
           ps.println("MAIL FROM: " + afzender);
           ........   
This does not work.
It seems as if a direct socket connection is not possible.
Is that correct?
If so, is there an indirect way to establisch the connection and sending the
mail?

Thanks for any help.
Rico - 10 Mar 2006 06:27 GMT
> public void MailerGroeps()
>  {  
[quoted text clipped - 18 lines]
> If so, is there an indirect way to establisch the connection and sending the
> mail?

Dude.. :-|
I like to think of JavaMail as being easy to use. jakarta-commons-email is
pretty nice too, especially for your purpose.. Sockets (??!!)

Btw.. some specific error message would be more helpful than
"This does not work."
Just a wild guess.. is there a firewall blocking you from accessing a SMTP
server outside of the network?

Rico.
Gordon Beaton - 10 Mar 2006 07:04 GMT
> I want tot add a mailfunction to my java-application. The
> application runs on an local nework.Students use it to sign up; the
> application places them in groupes, and on lists/ waitinglists. I
> want to send them by mail these lists. I use a Socket connection,
> from the local network to the mailserver.

[...]

> It seems as if a direct socket connection is not possible.

If a direct socket connection were not possible, how do you think
anyone *ever* manages to send mail?

Since you haven't given any indication *how* it fails, here are some
clues to help you help yourself:

- read RFC2821 describing SMTP. In particular, make sure you are
 sending the correct line endings (CRLF) after each command, instead
 of hoping that PrintStream gets it right.

- read and display the server's responses to your commands in order to
 get an idea of what is failing.

That said, you might consider using JavaMail instead of reinventing
the wheel.

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e

Loek Raemakers - 10 Mar 2006 20:19 GMT
Wheels ( let it be old ones :-) ) are rolling.
I solved my problem that was not so much a Socket problem but
a SMTP command problem.
I implemented a method to read the server response.
Got a sytax error, did read the RFC2821 and that's it.
Thanks to Gordon
Thanks to Rico


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.