Send Mail using JAVA
You don't have to use SMTP server name for your PC, you have to use external email server, for example, gmail, yahoo, etc. You can set up mail server on you computer, but it is out of the question. In your case, you have to register new email in free mail system, and use it smtp server and port. You can google more about JavaMail API examples: cafeaulait, vipan
xavierkcb
Updated on September 16, 2022Comments
-
xavierkcb over 1 year
Hi i would like to send a simple mail using java.. So i downloaded mail.jar and activation.jar file and i wrote simple program to send it.
My Simple mail program compiles successfully.. But when i run it shows the following error.
javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25; nested exception is: java.net.ConnectException: Connection refused: connect
My doubt is how to find the SMTP server name for my PC? I searched in site but didnt get anything clearly..
Please make me to travel in a right direction...
With regards
Xavier KCB
-
Mark Rotteveel about 12 years-1: TS needs to configure JavaMail to use the SMTP server of his ISP, not install a local SMTP server
-
Jan Gräfen about 12 yearsIf he tries to connect to localhost:25 he obviously don't want to sent emails from his ISP, but rather from his server or whatever. So your -1 is kind of random to me.
-
Mark Rotteveel about 12 yearsIf you don't configure JavaMail correctly (as in: don't set the server) then it defaults to localhost
-
StackFlowed over 9 yearsYou might want to add some explanation and not just throw some code out there.