jsp 的程序:
<%@ page
import=" javax.mail.*, javax.mail.internet.*, javax.activation.*,java.util.*"
%>
<html>
<head>
<TITLE>JSP meets JavaMail, what a sweet combo.</TITLE>
</HEAD>
<BODY>
<%
String from=request.getParameter("from");
String to=request.getParameter("to");String subject=new String(request.getParameter("subject").getBytes("ISO8859-1"),"GB2312");String text=new String(request.getParameter("neirong").getBytes("ISO8859-1"),"GB2312");try{
Properties props = System.getProperties();
Session sendMailSession;
Store store;
Transport transport;props.put("mail.smtp.host", "smtp.eyou.com");
sendMailSession = Session.getInstance(props, null);Message newMessage = new MimeMessage(sendMailSession);
newMessage.setFrom(new InternetAddress(from));
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
newMessage.setSubject(subject);
newMessage.setText(text);
transport = sendMailSession.getTransport("smtp");
transport.send(newMessage);
%>
<P>Your mail has been sent.</P>
<%
}
catch(MessagingException m)
{
out.println(m.toString());
}
%>
</BODY>
</HTML> 

解决方案 »

  1.   

    props.put("mail.smtp.host", "smtp.eyou.com");
    这里的问题吧,你应该使用参数来设置正确的smtp服务器的
      

  2.   

    ping能通吗?是不是网络的问题。
      

  3.   

    我自己写的程序:public class test {
      public static void main(String[] args) {
        String host = "smtp.pubinfo.com.cn";
        String from = "[email protected]";
        String to = "[email protected]";
        String username = "****";
        String password = "****";
        String subject = "中文测试Send Mail Testing";
        String content = "中文测试";    MailSend mailsend = new MailSend(host,from,to,username,password,subject,content);
        mailsend.msgSend();
        System.exit(0);
      }/////////////////////////////////////////////////////////
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.Properties;
    import javax.activation.*;public class MailSend{
      String host;
      String from;
      String to;
      String username;
      String password;
      String subject;
      String content;  public MailSend(String host,String from,String to,String username,
                      String password,String subject,String content){
        this.host = host;
        this.from = host;
        this.to   = to;
        this.username = username;
        this.password = password;
        this.subject  = subject;
        this.content  = content;
      }  public  void msgSend(){
           try{
        // Get system properties
           Properties props = System.getProperties();
        // Setup mail server
           props.put("mail.smtp.host", host);
            //Setup mail Auth
           Authenticator auth = new MyAuthenticator(username,password);
        // Get session
           Session session = Session.getDefaultInstance(props, auth);    // Define message
           MimeMessage message = new MimeMessage(session);    // Set the from address
           message.setFrom(new InternetAddress(from));    // Set the to address
           message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
        // Set the subject
           message.setSubject(subject);
        // Set the content
           message.setText(content);
        // Send message
               Transport.send(message);           System.out.println("\nMail was sent successfully.");
            }catch(Exception theException) {
                System.out.println(theException);
            }  }
    }////////////////////////////////////////
    import javax.mail.*;
    import java.util.*;public class MyAuthenticator extends Authenticator {
       String username, password;   public MyAuthenticator(String username,String password)
       {
         this.username = username;
         this.password = password;
       }
      public PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(username, password);
      }}