Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to send email using Java Program?

 
Anubhav Aeron
Greenhorn
Posts: 4
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am new to this Forum and to Java as well.. Let me know how to go about learning java. I am looking to make programs and gradually learn by executing practical examples.
I am also reading SCJP book for reference.

I want to make a java program which sends email. I've got the following code


// File Name SendEmail.java


I have a XAMPP host working. and I have attached the Jars for the JAF and the JavaMail. What else do I need to configure. I am unsure how to go about setting the SMTP. Though I have enabled it on my windows 7 laptop. But still getting the error.
Cannot open and load mail server properties file.
Cannot send email. javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
nested exception is:
java.net.ConnectException: Connection refused: connect



Thanks in advance.
Continues effort by me and little help from the experts will help me grow..
 
Tim Moores
Bartender
Posts: 2730
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems that you're not running a mail server on "localhost" on port 25. You can't send mail without a mail server.
 
Anubhav Aeron
Greenhorn
Posts: 4
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:It seems that you're not running a mail server on "localhost" on port 25. You can't send mail without a mail server.


Hi, Thanks for the quick reply.

How do I run a mail server on localhost. From the control panel I have enabled the IIS and Telnet Client and Server.
 
Tim Moores
Bartender
Posts: 2730
36
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neither IIS nor Telnet have anything to do with mail. You need something like Apache James.
 
Nam Ha Minh
Ranch Hand
Posts: 502
Eclipse IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to test, use a web mail account, such as GMail.
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:Neither IIS nor Telnet have anything to do with mail.

Not completely true. IIS is not just the web server, it also includes an FTP and SMTP server. However, they aren't started automatically. You would need to configure and start the SMTP server part of IIS. Or go for Apache James of course.
 
Anubhav Aeron
Greenhorn
Posts: 4
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:Neither IIS nor Telnet have anything to do with mail. You need something like Apache James.


Hi I am using apache Xampp. This includes Mercury mail server.
Still I am getting this error. How do i Check whether the mail server is working or not.
I did
telnet google.com 25
which says that its unable to connect..
 
Anubhav Aeron
Greenhorn
Posts: 4
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:
Tim Moores wrote:Neither IIS nor Telnet have anything to do with mail.

Not completely true. IIS is not just the web server, it also includes an FTP and SMTP server. However, they aren't started automatically. You would need to configure and start the SMTP server part of IIS. Or go for Apache James of course.


Hi,

I have started the SMTP server from the control panel already. But I am still getting the same error..
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anubhav Aeron wrote:How do i Check whether the mail server is working or not.
I did
telnet google.com 25
which says that its unable to connect..

Try telnet localhost 25. That will try to connect on port 25 on your own machine instead of whichever machines is behind google.com.
 
Raphael Okochu
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Aeron, you can test your javamail code using Mock-javamail without an actual working mail server.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic