Send mail
Sending mail through Java is easy. After you've installed the Java mail you're ready to go.
The send mail jsp:
<%@ page import="javax.mail.*" %> //import necessary libraries
<%@ page import="javax.mail.internet.*"%>
<%
String messageText = "My message";
String subject = "My title";
//Get system properties
Properties props = System.getProperties();
//Setup mail server
props.put("mail.smtp.host", "mail.yourhost.com");
// Get session
Session sesion = Session.getDefaultInstance(props, null);
// Define message
MimeMessage message = new MimeMessage(sesion);
message.setFrom(new InternetAddress(name@example.com));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(friend@example.com));
message.setSubject(subject);
message.setText(messageText);
// Send message
Transport.send(message);
%>
The mail.smtp.host is usually your isp's mailserver.
If the mailserver requires login you can add this:
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.username", "myUsername");
props.put("mail.smtp.password", "myPassword");
I strongly recommend you read Mail form and spamming before you use this code and implement this on your website. It contains tips on how to avoid turning your code in to a spammers paradise.