tags:

views:

140

answers:

5

is there an easy way to send email from java code ?

A: 

There are several ways to do that, best way is to use java mail. Look in this example for more info: http://www.javacommerce.com/displaypage.jsp?name=javamail.sql&id=18274

Tal
+5  A: 

You can use JavaMail or CommonsEmail (which is built on top of JavaMail)

Here is a simple example with Commons Mail, taken from this page :

SimpleEmail email = new SimpleEmail();
email.setHostName("mail.myserver.com");
email.addTo("[email protected]", "John Doe");
email.setFrom("[email protected]", "Me");
email.setSubject("Test message");
email.setMsg("This is a simple test of commons-email");
email.send();
Valentin Rocher
+1  A: 

If you want a bare to-the-point mailing API and/or want to be able to reach POP3 as well instead of only SMTP, have a look at JavaMail API. How to use it is covered in its excellent FAQ.

If you want a less bloated and more convenient API to send mails, head to Apache Commons Email which in turn is built on top of JavaMail API. How to use it is covered in its User Guide.

BalusC
A: 

Try the standard JavaMail API! There seems to be a quickstart

Karussell
A: 

There's a good short course about it: "jGuru: Fundamentals of the JavaMail API" - try it out.

it contains code snippets as well as explanations of them and of the Mail protocols (in case the dev. doesn't know how each one of them behaves).

moondowner