即使我写smtp.163.net还是一样,会出现错误
props.put("mail.smtp.host", "smtp.163.net");

解决方案 »

  1.   

    JavaMail API发邮件
    一:条件 必须下载sun公司的JavaMail API包,地址为:http://java.sun.com/products/javamail/
    我这里用的是1.2版本,将相关包(jar文件)加到CLASSPATH中
    二:该程序非常简单,不需要我们考虑很多地层的东西,因为API都帮我们做好了这些事情,下面是一个简单的发邮件的Servlet:(对于熟悉的人来说,恐怕是再简单不过了的一个servlet)
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*; 
    import sun.net.smtp.*; 
    public class SendMailServlet extends HttpServlet { 
    public static String MAIL_FROM = "from"; 
    public static String MAIL_TO = "to"; 
    public static String MAIL_SUBJECT = "subject"; 
    public static String MAIL_BODY = "body"; 
    public static String MAIL_HOST = "mailhost"; 
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException 
    {
    resp.setContentType("text/html; charset=gb2312"); 
    PrintWriter out = resp.getWriter(); 
    out.println("<form method=POST action=\"" + req.getRequestURI() + "\">"); 
    out.println("<table>");
    out.println("<tr><td>send mail server:</td>"); 
    out.println("<td><input type=text name=" + MAIL_HOST + " size=30></td></tr>"); 
    out.println("<tr><td>from:</td>"); 
    out.println("<td><input type=text name=" + MAIL_FROM + " size=30></td></tr>"); 
    out.println("<tr><td>to:</td>"); 
    out.println("<td><input type=text name=" + MAIL_TO + " size=30></td></tr>");
    out.println("<tr><td>subject:</td>"); 
    out.println("<td><input type=text name=" + MAIL_SUBJECT + " size=30></td></tr>"); 
    out.println("<tr><td>text:</td>"); 
    out.println("<td><textarea name=" + MAIL_BODY + " cols=40 rows=10></textarea></td></tr>"); 
    out.println("</table><br>"); 
    out.println("<input type=submit value=\"Send\">"); 
    out.println("<input type=reset value=\"Reset\">"); 
    out.println("</form>");
    out.flush();

    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException,IOException 

    resp.setContentType("text/html; charset=gb2312"); 
    PrintWriter out = new PrintWriter(resp.getOutputStream()); 
    String from = req.getParameter(MAIL_FROM); 
    String to = req.getParameter(MAIL_TO); 
    String subject = req.getParameter(MAIL_SUBJECT); 
    String body = req.getParameter(MAIL_BODY); 
    String mailhost = req.getParameter(MAIL_HOST); 
    try 

    SmtpClient mailer = new SmtpClient(mailhost); 
    mailer.from(from);
    mailer.to(to);
    PrintStream ps = mailer.startMessage();
    ps.println("From: " + from);
    ps.println("To: " + to); 
    ps.println("Subject: " + subject); 
    ps.println(body); 
    mailer.closeServer(); 
    out.println("Success!"); 

    catch (Exception ex) 

    out.println("An error about:" + ex.getMessage()); 
    }
    out.flush();
    }
    public void init(ServletConfig cfg) throws ServletException 
    {
    super.init(cfg);
    }
    public void destroy() 
    {
    super.destroy(); 
    }

    --------------------------
    让生命时刻充满着激情!
      

  2.   

    写smtp,如果需要身份验证的话必须提供身份验证
      

  3.   

    http://www.csdn.net/develop/Read_Article.asp?Id=14929
      

  4.   

    phoenix7789(火鸟*有了★再回去灌水):我刚学jsp没几天,我的那个servlet是怎么用的,我只会用javabeans
      

  5.   

    感谢,csdn中有没有javamail高手啊
      

  6.   

    http://www.csdn.net/develop/Read_Article.asp?Id=14929
    这个bean很好用
    支持附件,中文,html
      

  7.   

    我也出現和你一樣的問題http://expert.csdn.net/Expert/TopicView1.asp?id=2266476幫你頂一下
      

  8.   

    leshui(大象无形)(有物混成,先天地生):请问那个bean怎么用,我刚学jsp没几天,帮帮忙
      

  9.   

    String mailbody = "<meta http-equiv=Content-Type content=text/html; charset=gb2312>"+
            "<div align=center><a href=http://www.csdn.net> csdn </a></div>";    sendMail themail = new sendMail("smtp.msn.com");
        themail.setNeedAuth(true);    if(themail.setSubject("标题") == false) return;
        if(themail.setBody(mailbody) == false) return;
        if(themail.setTo("[email protected]") == false) return;
        if(themail.setFrom("[email protected]") == false) return;
        if(themail.addFileAffix("c:\\boot.ini") == false) return;
        themail.setNamePass("user","password");    if(themail.sendout() == false) return;    
      

  10.   

    把你下载的javamail1.3.1包中lib下的smtp.jar等加到你的类路径中去,如果你用的是tomcat,把它考到classes/lib下或则tomcat/common/lib下