http://www.netyi.net/in.asp?id=lockllb//大量的教程!几乎包含了有关于计算机的一切!!!!!!

解决方案 »

  1.   

    <%@ page contentType="text/html;charset=gb2312" %>
    <%@ page import="javax.mail.*"%>
    <%@ page import="javax.mail.internet.*"%>
    <%@ page import="javax.activation.*"%> 
    <%@ page import="java.util.*"%> 
    <HTML> 
    <head> <TITLE>JSP meets JavaMail, what a sweet combo.</TITLE>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </HEAD>
    <BODY> 
    <%!  
    //byte[] subjectTemp= request.getParameter("Subject").getBytes("ISO8859_1");
    public class PopupAuthenticator extends Authenticator { 
    public PasswordAuthentication getPasswordAuthentication() {
    String username, password; 
    username = "user";
    password = "pass"; 
    return new PasswordAuthentication(username, password);
    }

    %>
    <%!
    public String toChi(String input) 
    {
        try 
        {
            byte[] bytes = input.getBytes("ISO8859-1");
            return new String(bytes);
        }
        catch(Exception ex) 
        {
        }
        return null;
    }
    %><% 
    try{ 
    String name = request.getParameter("Name");
    String subject = request.getParameter("Subject");
    String Hi=request.getParameter("Body"); 
    byte[] tmpbyte=Hi.getBytes("ISO8859_1"); 
    Hi=new 
    String(tmpbyte); 
    // out.print(Hi);  //String body = (request.getParameter("Body").getBytes("ISO8859-1"));
    Properties props = new Properties();
    Session sendMailSession; Store store; 
    Transport transport; 
    props.put("mail.smtp.host","yourhost"); 
    props.put("mail.smtp.auth","true"); 
    Authenticator auth = new PopupAuthenticator(); 
    sendMailSession = Session.getInstance(props,auth); 
    sendMailSession.setDebug(true); 
    Message newMessage = new MimeMessage(sendMailSession); 
    newMessage.setFrom(new InternetAddress("frommail"));
    newMessage.setRecipient(
    Message.RecipientType.TO, new InternetAddress("tomail"));
    newMessage.setSubject(subject); 
    newMessage.setSentDate(new Date());
    //String body = ("hello are you你好啊.?");
    newMessage.setText(Hi);
    transport = sendMailSession.getTransport("smtp");
    transport.send(newMessage); 
    %>
    <P>Your mail has been sent.</P>
    <% 
    }  catch(MessagingException m) { 
    out.println(m.toString());

    %>
    </BODY> 
    </HTML>
    这是代码.如果到那里也有分送.解决一起结贴.