Ok well here is a better example then:
=================================================
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
/**
* Sends an email
* @author ****
*
*/
public final class EmailSender
{
/**
* Initialize
* @param theUser The user the mail is from (e.g. admin)
* @param theSMTPHost The SMTP server
* @param theFromAddr The email address the mail is sent from (e.g.
(e-mail address removed))
* @throws Exception if problem encountered
*/
public EmailSender(String theUser, String theSMTPHost, String
theFromAddr) throws Exception
{
//Set the host smtp address
Properties theProperties = new Properties();
theProperties.put("mail.smtp.user", theUser);
theProperties.put("mail.smtp.host", theSMTPHost);
try
{
myFromAddr = new InternetAddress(theFromAddr);
}
catch(AddressException e)
{
throw new Exception("Failed to obtain sender address");
}
mySession = Session.getDefaultInstance(theProperties, null);
}
/**
* Sends an Email
* @param theRecipients the recipients
* @param theSubject the email subject
* @param theMessage the email message
* @throws MessagingException on exception
*/
public void sendMail( String[] theRecipients, String theSubject,
String theMessage) throws MessagingException
{
if(theRecipients.length>0)
{
// create a message
Message msg = new MimeMessage(mySession);
// set the from and to address
msg.setFrom(myFromAddr);
InternetAddress[] addressTo = new
InternetAddress[theRecipients.length];
for (int i = 0; i < theRecipients.length; i++)
{
addressTo
= new InternetAddress(theRecipients);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(theSubject);
msg.setContent(theMessage, "text/plain");
Transport.send(msg);
}
//else nothing to send
}
/** Session **/
private Session mySession;
/** the from address */
private InternetAddress myFromAddr;
}
=============================================================
You will need the java mail package (
http://java.sun.com/products/javamail/ )
The class can be ran easily, something like:
EmailSender myEmailSender = new EmailSender("admin",
"127.0.0.1", "(e-mail address removed)");
//Email body
String body="This is an example email from java.";
String[] theRecipients = {"(e-mail address removed)"};
myEmailSender.sendMail(theRecipients, "My Email Test",
body);
So it is just a case of having a SMTP server you can use really.