Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send Mail using JAVA

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

like image 962
xavierkcb Avatar asked Mar 10 '12 10:03

xavierkcb


People also ask

What is SMTP in Java?

SMTP is an acronym for Simple Mail Transfer Protocol. It is an Internet standard for electronic mail (e-mail) transmission across Internet Protocol (IP) networks.

What is the use of MimeMessage in Java?

Class MimeMessage. This class represents a MIME style email message. It implements the Message abstract class and the MimePart interface. Clients wanting to create new MIME style messages will instantiate an empty MimeMessage object and then fill it with appropriate attributes and content.

Can you send Java files over email?

For sending email with attachment, JavaMail API provides some useful classes like BodyPart, MimeBodyPart etc. For better understanding of this example, learn the steps of sending email using JavaMail API first. For sending the email using JavaMail API, you need to load the two jar files: mail.


1 Answers

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

like image 173
MikhailSP Avatar answered Oct 03 '22 23:10

MikhailSP