Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

how to send email using Java Program?

 
Greenhorn
Posts: 4
Eclipse IDE Oracle Java
  • 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..
 
Saloon Keeper
Posts: 6525
160
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • 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 Oracle Java
  • 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
Saloon Keeper
Posts: 6525
160
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • 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.
 
Ranch Hand
Posts: 530
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to test, use a web mail account, such as GMail.
 
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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 Oracle Java
  • 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 Oracle Java
  • 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
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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.
 
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.
 
I just had the craziest dream. This tiny ad was in it.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic