tags:

views:

201

answers:

3

Hi
I have designed a chat application where different users can create the account, but I do not know how to send a confirmation email to the users. Since I collect their e-mail address in the registration form, how can I send mail to those addresses in Java?

A: 

This looks like a good site for you: http://www.javacommerce.com/displaypage.jsp?name=javamail.sql&id=18274

Google 'send mail java'

Dante
+4  A: 

First of all, you need a SMTP server. It's required to be able to send emails. You can make use of the SMTP server associated with your own existing email account, such as the one from your ISP or public mailboxes like Gmail, Yahoo, etc. You can find SMTP connection details at their documentation. You usually just need to know the hostname and the port number. The login details are just the same as from your email account.

You're however restricted to using your own address in the From field of the email and usually also in the amount of emails you're allowed to send at certain intervals. If you'd like to get around this, then you need to install your own SMTP server, for example Apache James, which is Java based, or Microsoft Exchange and so on.

Then, to send an email using Java code, you would need the JavaMail API or the more convenienced Apache Commons Email.

BalusC
A: 

The easiest way of doing this really depends on the environment that your JVM is running in.

If you're running in a standard Linux/UNIX environment and don't want to faff about with extra libraries, then one way is just to "manually" call sendmail (e.g. via ProcessBuilder). As with executing commands generally, you just need to be slightly careful that you don't just pass user input as parameters without screening them.

Neil Coffey
The main intent of Java is to be platformindependent. That's why under each JavaMail exist :)
BalusC
Yes, if you actually *need* that platform independency and it's appropriate to expect it in the case in question. If it's your server-side code, then whatever language you program in, in reality it will be coded for your particular server environment in all sorts of places.
Neil Coffey