aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes how to send email using Java Program? 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 "how to send email using Java Program?" Watch "how to send email using Java Program?" New topic
Author

how to send email using Java Program?

Anubhav Aeron
Greenhorn

Joined: Feb 25, 2012
Posts: 4

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
Rancher

Joined: Sep 21, 2011
Posts: 2408
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

Joined: Feb 25, 2012
Posts: 4

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
Rancher

Joined: Sep 21, 2011
Posts: 2408
Neither IIS nor Telnet have anything to do with mail. You need something like Apache James.
Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 498

If you want to test, use a web mail account, such as GMail.

PM Me If You Want to get Urgent Help on Java Programming
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19695
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Anubhav Aeron
Greenhorn

Joined: Feb 25, 2012
Posts: 4

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

Joined: Feb 25, 2012
Posts: 4

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

Joined: Oct 27, 2005
Posts: 19695
    
  20

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

Joined: Jul 17, 2009
Posts: 22
Hi Aeron, you can test your javamail code using Mock-javamail without an actual working mail server.


SCJP 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to send email using Java Program?