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?
views:
201answers:
3This looks like a good site for you: http://www.javacommerce.com/displaypage.jsp?name=javamail.sql&id=18274
Google 'send mail java'
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.
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.