File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes Unable to send mail through mail api 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 "Unable to send mail through mail api" Watch "Unable to send mail through mail api" New topic
Author

Unable to send mail through mail api

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Hi,

I am using the following code and tried to send an attachment with the mail. But when i run this is linux, no error occured . But mail has not been sent. But when i tried in windows machine, the following error occured:



javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1282)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
at SendMultiPartMail.main(SendMultiPartMail.java:67)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:232)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1250)
... 7 more





Please help me to solve this.
Thanks
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Is there an SMTP server running on port 25 on localhost?
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
How to check smtp port in windows?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19784
    
  20

If you need to ask then I can tell you that there isn't an SMTP server running. Unless you have a Server edition you would need to install IIS and its SMTP server explicitly, and I doubt you have done so.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Windows by default does not have an SMTP server, so if you didn't install one then there isn't one.

You should be able to use your company's mail server instead (in which case you will need to add authentication code to your program).
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Hi,

Thank you for your replies. I have used my company's mail server in the place of host. Is that correct? If not where should i use that?because I didn't install any smtp server.


Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19784
    
  20

The company's SMTP server is a good choice. I use ours for all my emailing code.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to send mail through mail api