• Post Reply Bookmark Topic Watch Topic
  • New Topic

Javamail problem

 
Joshua Cloch
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am trying to send an email by javamail through yahoo SMTP mail server,but I have got the exception below when connecting to the server:

javax.servlet.ServletException: Could not connect to SMTP host: smtp.mail.yahoo.com, port: 25


Does anybody have any ideas in this problem? Or,this happened because Yahoo does not support the connection to its mail server in this way?

if yes,could you please suggest another mail server? I just wanna test sending and receiving mails through javamail.Do I need to find such a mail server to test?

Thanks very much!
 
kwame Iwegbue
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joshua, I had a similar problem in January. Here is an excerpt of some very useful information, giving to me by fellow ranch hand here - Paul Clapham:


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.
 
Joshua Cloch
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much.
The only problem is how to get authorized by the mail server? Does it mean that my IP addess is registered by the mail server then the request from my computer is approved?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Authentication to email servers usually works by username and password. So you need to have a valid account on the server. Checking the IP address of the sender may be additional feature (e.g. in a company or university setting), but it's less common.
 
Joshua Cloch
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again!

If I have an account of the mail server in my university, how to add the user and password in the code? could you please give me some sample code?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The J2EE FAQ has some useful JavaMail links. The tutorial at java.sun.com in particular has many code examples.
 
Joshua Cloch
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many many thanks...
 
Khaled El Ghayesh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, does that mean that if someone like me, with no mail or anything, tries to send an e-mail through JavaMail it won't work coz I should have access to a mail server ??

When I tried this code,


I got this message javax.mail.MessagingException: Could not connect to SMTP host: yourmail.yourserver.com, port: 25, response: -1
I dunno should I change the yourmail, yourserver fields or what ??


For example I can't just fool around and send automated mails to myself and my friends??


Note: That's not what I want for sure, but I am just exaggerating it !!
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Khaled, welcome to JavaRanch. If you have any questions, please start a new thread instead of tacking on to an old existing one.

Yes, to send emails you need an email server. You can of course run one on your local machine, e.g. Apache James, if you want a Java solution.
 
Khaled El Ghayesh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Khaled, welcome to JavaRanch. If you have any questions, please start a new thread instead of tacking on to an old existing one.

Yes, to send emails you need an email server. You can of course run one on your local machine, e.g. Apache James, if you want a Java solution.


I am sorry. The next time i'll open a new thread.
I had another related question.
What should I write here

Should I write the name of the mail server or what?? And what should I do with James Apache ??

Excuse me if the questions are too naive, but I am totally new to the topic.

Thanks,
Khaled
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Should I write the name of the mail server or what?? And what should I do with James Apache ??


Yes, that's the DNS name of the mail server. If you run it on your local machine, you can use "localhost" or "127.0.0.1". Depending on what kind of machine/OS you have, you may not be able to run a server on port 25 (which is the standard SMTP port). In that case, use a port above 1024, and change the respective property as well.

Apache James is a mail server. Since you don't have, but need one, you can install and use it. Any other mail server will do as well, of course.
 
Tilak Tilak
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.auth", "true"); // esto es importante
props.put("mail.debug", "true"); // la informaci�n debug se mostrar� via System.out
props.put("mail.smtp.starttls.enable", "true"); // esto tambi�n es importante
props.put("mail.smtp.port", "465");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");


Use these properties, it worked for me. I'm able to send mail to anyone i wish to.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!