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: 2407
posted
1
Is there an SMTP server running on port 25 on localhost?
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.
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
posted
0
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.