File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes SocketException with JavaMail Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "SocketException with JavaMail" Watch "SocketException with JavaMail" New topic
Author

SocketException with JavaMail

kwame Iwegbue
Ranch Hand

Joined: Sep 02, 2000
Posts: 197
I'm trying to write a simple java mail program to send only with the foll code



but i keep getting the following error:



Who dares, wins! (SAS motto)
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

This is not a Servlet issue.
Moving to Other Java APIs where the Javamail savvy hang out.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41791
    
  62
Since you're trying to connect to "localhost", you must have a mail server under your control on your local machine. Can you connect to it using other means (e.g. a mail client)? Do any messages show up in its log files?


Ping & DNS - my free Android networking tools app
kwame Iwegbue
Ranch Hand

Joined: Sep 02, 2000
Posts: 197
I'm not trying to connect through local host. I would simply like to have simple application for sending email. I will later make it a servlet. can you pls help with some ideas.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18563
    
    8

Originally posted by kwame Iwegbue:
I'm not trying to connect through local host.
But the debug output from JavaMail says specifically
trying to connect to host "localhost", port 25
You need to set the "smtp.mail.host" property to the name or IP address of the computer where your SMTP server is running. Check with its administrator if you are not sure of what name or address you should be using.
kwame Iwegbue
Ranch Hand

Joined: Sep 02, 2000
Posts: 197
props.put("smtp.mail.host", host);

I thought this refers to the receipients smtp and host. for example when sending mail to someone with yahoo email, then should use props.put("smtp.yahoo.com", 'mail.yahoo.com');
or something like this
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18563
    
    8

No. It is the name of the server that YOU will be using to SEND e-mail messages.

So, before you spend any more time on this project, make sure that you have access to one. Talk to the administrator of the server to make sure that you can use it.
kwame Iwegbue
Ranch Hand

Joined: Sep 02, 2000
Posts: 197
Thank you paul.

so i guess from a regular desktop/private computer, that would be "localhost".
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14139
    
  18

Originally posted by kwame Iwegbue:
Thank you paul.

so i guess from a regular desktop/private computer, that would be "localhost".

Yes, but you should ofcourse have mail server software running on your regular desktop/private computer (i.e., localhost) if you want to do that. If you don't have mail server software running, it's not going to work. Have a look at Apache Jakarta James for example, a free and open source mail server.
Originally posted by kwame Iwegbue:
props.put("smtp.mail.host", host);

I thought this refers to the receipients smtp and host. for example when sending mail to someone with yahoo email, then should use props.put("smtp.yahoo.com", 'mail.yahoo.com');
or something like this

No, it would be:

props.put("smtp.mail.host", "mail.yahoo.com");

if mail.yahoo.com is indeed an SMTP mail server that you can access.
[ January 16, 2006: Message edited by: Jesper de Jong ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18563
    
    8

Originally posted by kwame Iwegbue:
so i guess from a regular desktop/private computer, that would be "localhost".
Probably not.

Here's how e-mail works. You give your e-mail message to a mail server and tell it who the recipients are. It finds their mail server, if it can, and between the two servers your message gets transferred from your server to the recipients' server.

Now here's the problem with that idea. All of those e-mail servers are accessible from the Internet. They have to be so that they can find each other and transfer messages. That means that anybody anywhere on the Internet can connect to any e-mail server and ask it to send a message to anybody else. This ability has been abused by people named "spammers" who use other people's servers to send out mass mailings that try to cheat people. So public e-mail servers won't let your program use them to send messages unless you have been pre-approved in some way.

In your case you don't have your own server. And even if you install your own server it probably isn't going to be trusted by other servers, for various technical reasons (I'm not writing an entire magazine article here). If you don't have access to an SMTP server that already exists, then you are wasting your time. If you are writing this program for a company, then that company should have an e-mail server that you can use. As I already said, you need to talk to the administrator of that server to get yourself approved to use it. But if you're just writing it for personal use, you are going to find it a lot more difficult to get access to a server.
kwame Iwegbue
Ranch Hand

Joined: Sep 02, 2000
Posts: 197
thank you paul.

I finally got a hold of my comapany's SMTP, and the app works now!!!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: SocketException with JavaMail