• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How to send mail?

 
Greenhorn
Posts: 13
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi friendz,

I am using Java Mail API to send mail on my mail server but facing some problems. I kept extracted mail.jar and activation.jar files in classes directry of my application. Code generating the error is given below:

------------------------------------------------------------------------------------------

<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*"%>
<%
try{
Properties props = new Properties();
props.put("mail.smtp.host", "mail.yahoo.com");
Session s = Session.getDefaultInstance(props,null);


InternetAddress from = new InternetAddress("[email protected]");
InternetAddress to = new InternetAddress("[email protected]");

MimeMessage message = new MimeMessage(s);
message.setFrom(from);
message.addRecipient(Message.RecipientType.TO, to);

message.setSubject("My subject");
message.setText("My Text");
Transport.send(message);
}
catch(Exception e){
out.println(e.getMessage());
e.printStackTrace();
}
%>
-----------------------------------------------------------------------------------------
ERROR:
------------------------------------------------------------------------------------------

Could not connect to SMTP host: mail.yahoo.com, port: 25

------------------------------------------------------------------------------------------

I am using Apache Tomcat 5.5 to deploy and to run my application.
Please guide me for my mistake and all the necessary steps to follow to send text/formatted(Tabular Format) mail.

Thanks in advance
 
Sheriff
Posts: 28368
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's something about your network configuration that prevents your program from connecting to that server. You should read the JavaMail FAQ for more information on this problem and many others that you are likely to encounter.
 
Karuna chauhan
Greenhorn
Posts: 13
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply paul!

I must consider your suggestion but it would be greatfull if you could give some idea about network configuration nedded for application to be connected to the server.
 
Paul Clapham
Sheriff
Posts: 28368
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have no idea about how your network is organized. You could ask the person in charge of the network. Or you could read the FAQ. I strongly recommend that anyway as you will learn other things about how e-mail works which you didn't know.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure that's the server you should be using? mail.yahoo.com is the address of the web server that runs the webmail part of Yahoo mail; I'm not sure it's the correct address for SMTP as well.

Also, be aware that you need to use authentication if you want to connect to public SMTP servers.

Also note that Yahoo Mail is accessible by SMTP only if you have a premium account that you're paying for (I think it's called YahooPlus).
 
Karuna chauhan
Greenhorn
Posts: 13
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with you ulf, but i'm using my mail server. I've written "mail.yahoo.com" jus to illustrate the way i'm putting the name of my mail server.....

Anywayz! friend could you tell me how to test my code on localhost when the address of my localhost is - "http://localhost:6060". Also i want to specify that i'm using Apache Tomcat 5.5 server.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Karuna chauhan wrote:I agree with you ulf, but i'm using my mail server. I've written "mail.yahoo.com" jus to illustrate the way i'm putting the name of my mail server.....

Anywayz! friend could you tell me how to test my code on localhost when the address of my localhost is - "http://localhost:6060". Also i want to specify that i'm using Apache Tomcat 5.5 server.



Just change the mail.smtp.host property (see the JavaMail docs linked above for how to set the port).
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

but i'm using my mail server. I've written "mail.yahoo.com" jus to illustrate the way i'm putting the name of my mail server.....


You should have mentioned that from the beginning, instead of leading us down this wrong path.

could you tell me how to test my code on localhost when the address of my localhost is - "http://localhost:6060". Also i want to specify that i'm using Apache Tomcat 5.5 server.


It doesn't matter which web server you're using - you need to have an SMTP server up and running. Above you said you're using your own mail server - on which machine is that running? If it's on the same machine where the code is running, you can just use "localhost" as the server name.
 
Karuna chauhan
Greenhorn
Posts: 13
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm really sorry ulf that i din't mentioned i'm using my mail server.

As you asked above- my mail server and my code both are on different machines.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In that case you can either use the IP address or the TCP/IP server name of the mail server.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic