Socket problem

L

Loek Raemakers

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.
 
R

Rico

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?

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.
 
G

Gordon Beaton

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
 
L

Loek Raemakers

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top