• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to send email using Java Program?

 
Greenhorn
Posts: 4
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7582
176
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to test, use a web mail account, such as GMail.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Aeron, you can test your javamail code using Mock-javamail without an actual working mail server.
 
There's a way to do it better - find it. -Edison. A better tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic