Send Mail using JAVA

11,405

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

Share:
11,405
xavierkcb
Author by

xavierkcb

Updated on September 16, 2022

Comments

  • xavierkcb
    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
    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
    Jan Gräfen about 12 years
    If 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
    Mark Rotteveel about 12 years
    If you don't configure JavaMail correctly (as in: don't set the server) then it defaults to localhost
  • StackFlowed
    StackFlowed over 9 years
    You might want to add some explanation and not just throw some code out there.