package sendmail;public class SmtpAuthenticator
    extends javax.mail.Authenticator {
//SMTP身份验证
  public javax.mail.PasswordAuthentication getPasswordAuthentication() {
    return new javax.mail.PasswordAuthentication("xhp999", "760303");
  }
}
<%@ page import=" sendmail.*,javax.mail.*, javax.mail.internet.*, javax.activation.*,java.util.*"%>
<html>
<head>
<TITLE>JSP meets JavaMail, what a sweet combo.</TITLE>
</head>
<body>
<%try{
Properties props = new Properties();
sendmail.SmtpAuthenticator s = new SmtpAuthenticator();
Session sendMailSession;
//javax.mail.PasswordAuthentication pass = new javax.mail.PasswordAuthentication("xhp999","760303");
Store store;Transport transport;
props.put("mail.smtp.host", "smtp.sohu.com");
props.put("mail.smtp.auth","true");//\u662F\u5426\u8FDB\u884C\u8EAB\u4EFD\u9A8C\u8BC1
sendMailSession = Session.getInstance(props,s);
//Session.getInstance()
Message newMessage = new MimeMessage(sendMailSession);
newMessage.setFrom(new InternetAddress(request.getParameter("from")));
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress ( request.getParameter ("to")));
newMessage.setSubject(request.getParameter("subject"));
newMessage.setSentDate(new Date());
newMessage.setText(request.getParameter("text"));
transport = sendMailSession.getTransport("smtp");
transport.send(newMessage);
%>
<P>Your mail has been sent.</P>
<%
}catch(MessagingException m)
{
out.println(m.toString());
}
%>
</body>
</html>下面是一个简单的html
<HTML>
<BODY>
<FORM action="SendEmail.jsp" method="post">
<TABLE align="center">
<TR>
<TD width="50%">
To:<BR><INPUT name="to" size="25">
</TD>
<TD width="50%">
From:<BR><INPUT name="from" size="25">
</TD>
</TR>
<TR>
<TD colspan="2">
Subject:<BR><INPUT name="subject" size="50">
</TD>
</TR>
<TR>
<TD colspan="2">
<P>Message:<BR>
<TEXTAREA name="text" rows=25 cols=85></TEXTAREA>
</P>
</TD>
</TR>
</TABLE>
<INPUT type="submit" name="cb_submit" value=" Send ">
<INPUT type="reset" name="cb_reset" value=" Clear ">
</FORM>
</BODY>
</HTML>