出错信息:
Sample JSP email Utility Using JavaMail javax.mail.SendFailedException: Sending failed; nested exception is: class javax.mail.MessagingException: 553 You are not authorized to send mail as >, authentication is required

解决方案 »

  1.   

    有的时候是这样:(更换表单里面的邮箱地址)
    Sample JSP email Utility Using JavaMail javax.mail.SendFailedException: Sending failed; nested exception is: class javax.mail.MessagingException: 550 : Invalid User
      

  2.   

    需要你的邮件服务器的用户名和密码的人证。在你的MAIL.jar包中一个AUTHOR开头的类,继承它,再认证,OK
      

  3.   

    props.put("mail.smtp.auth", "true");
      

  4.   

    http://www.cn-java.com/target/news.php?news_id=1511
      

  5.   

    你的163邮箱需要安全认证才能发送邮件,试试这个:
    transport = sendMailSession.getTransport("smtp"); 
    transport.connect("smtp.163.com",25,"your email name","your email password");
    transport.sendMessage(msg,InternetAddress.parse("your send email1,your send email1......",true));
      

  6.   

    html:
    <html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
    <title>撰写邮件</title> 
    </head> 
    <body> 
    <form action="testall.jsp" method="post" name="form1"> 
    <table width="424" border="0" align="center" cellspacing="1" bgcolor="#006600" class="black" height="287"> <tr bgcolor="#FFFFFF"> 
    <td width="102" height="29"><font face="宋体"><font size="3">收信人</font>:</font></td> 
    <td width="308" height="23"> <input name="to1" type="text" id="to1" size="19"><font size="2"><i><font face="Basemic Times">@&nbsp; 
      </font></i></font><input name="to2" type="text" id="to2" size="17"></td> 
    </tr> <tr bgcolor="#FFFFFF"> 
    <td width="102" height="12"><font size="3"><font face="宋体">寄信人</font></font><font face="宋体">:</font></td> 
    <td width="308" height="23"> <input name="from1" type="text" id="from1" size="19"><i><font face="Basemic Times" size="2">@&nbsp; 
      </font></i><input name="from2" type="text" id="from2" size="17"></td>  
    </tr> <tr bgcolor="#FFFFFF"> 
    <td width="102" height="14"><font size="3"><font face="宋体">用户名</font></font><font face="宋体">:</font></td> 
    <td width="308" height="25"> <input name="yhm" type="text" id="yhm" size="41">  
    </tr>  <tr bgcolor="#FFFFFF">
    <td width="102" height="14"><font size="3"><font face="宋体">密&nbsp; 码</font></font><font face="宋体">:</font></td> 
    <td width="308" height="25"> <input name="mm" type="text" id="mm" size="41"> 
    </tr><tr bgcolor="#FFFFFF"> 
    <td width="102" height="25"><font size="3" face="宋体">主&nbsp; 题:</font></td> 
    <td width="308" height="25"> <input name="title" type="text" id="title" size="41"></td> 
    </tr> 
    <tr> 
    <td height="25" colspan="2" bgcolor="#FFFFFF" width="401"><font size="3"><font face="宋体">信件类型</font>:&nbsp; 
      </font><select name="emailtype" id="emailtype" size="1">         
    <option value="text/plain">Text</option> 
    <option value="text/html">Html</option> 
    <option selected>-Select-</option>
    </select></td> 
    </tr> 
    <tr> 
    <td height="63" colspan="2" bgcolor="#FFFFFF" width="401"><textarea name="content" cols="56" rows="8" id="content"></textarea></td> 
    </tr> <tr align="center" valign="bottom"> 
    <td colspan="2" bgcolor="#FFFFFF" width="401" height="33">
      <p align="left"><font size="3">附件(本地):</font>    
       <input name="fj2" type="file" id="fj2" size="47"></p>    
    </td> 
    </tr> 
    <tr align="center"> 
    <td colspan="2" bgcolor="#FFFFFF" width="401" height="11"> <input type="submit" name="Submit" value="发送"> 
    <input type="reset" name="Submit2" value="重置"></td> 
    </tr> 
    </table> 
    </form> 
    </body> 
    </html> 
    jsp:
    <%@ page contentType="text/html;charset=GB2312" %> 
    <%request.setCharacterEncoding("gb2312");%> 
    <%@ page import="java.util.*,javax.mail.*"%> 
    <%@ page import="javax.mail.internet.*"%> 
    <%@ page import="javax.activation.*"%><!--要发送附件必须引入该库--> <html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
    <title>发送成功</title> 
    </head> 
    <body> 
    <% 
    try{ 
    String tto1=request.getParameter("to1"); 
    String tto2=request.getParameter("to2"); 
    String tfrom1=request.getParameter("from1"); 
    String tfrom2=request.getParameter("from2"); 
    String tyhm=request.getParameter("yhm"); 
    String tmm=request.getParameter("mm"); 
    String ttitle=request.getParameter("title"); 
    String emailtype=request.getParameter("emailtype");//获取email类型 
    String tcontent=request.getParameter("content"); 
    //String tfj1=request.getParameter("fj1"); 
    String tfj2=request.getParameter("fj2"); 
    String tfj3=request.getParameter("fj3"); String smtptype="";
    if(tfrom2.equals("163.com"))
    {smtptype="smtp.163.com";
      }//支持
      else if(tfrom2.equals("126.com"))
    {smtptype="smtp.126.com";
      }//支持
      else if(tfrom2.equals("21cn.com"))
    {smtptype="smtp.21cn.com";
      }//支持
      else if(tfrom2.equals("yahoo.com.cn"))
    {smtptype="smtp.mail.yahoo.com.cn";
      }//支持
    else if(tfrom2.equals("tom.com"))
    {smtptype="smtp.tom.com";
      }//支持
      else if(tfrom2.equals("263.net"))
    {smtptype="smtp.263.net";
      }//未试
      else if(tfrom2.equals("mail.china.com"))
    {smtptype="mail.china.com";
      }//不支持
      else if(tfrom2.equals("sina.com"))
    {smtptype="smtp.sina.com";
      }//不支持
      Properties props=new Properties(); 
    props.put("mail.smtp.host",smtptype); 
    props.put("mail.smtp.auth","true"); 
    Session s=Session.getInstance(props); 
    s.setDebug(true); MimeMessage message=new MimeMessage(s); //给消息对象设置发件人/收件人/主题/发信时间 
    InternetAddress from=new InternetAddress(tfrom1+"@"+tfrom2,tfrom1); 
    message.setFrom(from); 
    InternetAddress to=new InternetAddress(tto1+"@"+tto2); 
    message.setRecipient(Message.RecipientType.TO,to); 
    message.setSubject(ttitle); 
    message.setSentDate(new Date()); Multipart mm=new MimeMultipart();//新建一个MimeMultipart对象用来存放多个BodyPart对象 //设置信件文本内容 
    BodyPart mdp=new MimeBodyPart();//新建一个存放信件内容的BodyPart对象 
    mdp.setContent(tcontent,emailtype+";charset=gb2312");//给BodyPart对象设置内容和格式/编码方式 
    mm.addBodyPart(mdp);//将含有信件内容的BodyPart加入到MimeMultipart对象中 //设置信件的附件1(自定义附件:直接将所设文本内容加到自定义文件中作为附件发送) 
    //mdp=new MimeBodyPart();//新建一个存放附件的BodyPart 
    DataHandler dh=new DataHandler(tfj2,"text/plain;charset=gb2312"); 
    //新建一个DataHandler对象,并设置其内容和格式/编码方式 
    //mdp.setFileName("text.txt");//加上这句将作为附件发送,否则将作为信件的文本内容 
    //mdp.setDataHandler(dh);//给BodyPart对象设置内容为dh 
    //mm.addBodyPart(mdp);//将含有附件的BodyPart加入到MimeMultipart对象中 //设置信件的附件2(用本地上的文件作为附件) 
    mdp=new MimeBodyPart(); 
    FileDataSource fds=new FileDataSource(tfj2); 
    dh=new DataHandler(fds); 
    int ddd=tfj2.lastIndexOf("\\"); 
    String fname=tfj2.substring(ddd);//提取文件名 
    String ffname=new String(fname.getBytes("gb2312"),"ISO8859-1");//处理文件名是中文的情况 
    mdp.setFileName(ffname);//可以和原文件名不一致,但最好一样 
    mdp.setDataHandler(dh); 
    mm.addBodyPart(mdp); 
    //设置信件的附件3(用远程文件作为附件) 
    //mdp=new MimeBodyPart(); 
    /*URL urlfj=new URL(tfj3); 
    URLDataSource ur=new URLDataSource(urlfj); 
    //注:这里用的参数只能为URL对象,不能为URL字串,在前面类介绍时有误(请谅解),这里纠正一下. 
    dh=new DataHandler(ur); 
    int ttt=tfj3.lastIndexOf("/"); 
    String urlname=tfj3.substring(ttt); 
    //String urlfname=new String(urlname.getBytes("gb2312"),"ISO8859-1");//不知怎么回事,这里不能处理中文问题 
    mdp.setFileName(urlname); 
    mdp.setDataHandler(dh); 
    mm.addBodyPart(mdp); 
    */
    message.setContent(mm);//把mm作为消息对象的内容 message.saveChanges(); 
    Transport transport=s.getTransport("smtp"); 
    transport.connect(smtptype,tyhm,tmm); 
    transport.sendMessage(message,message.getAllRecipients()); 
    transport.close(); %> 
    <div align="center"> 
    <p><font color="#FF6600">发送成功!</font></p> <br> 
    <a href="m.html">再发一封</a> </p> 
    </div> 
    <% 
    }catch(MessagingException e){ 
    out.println(e.toString()); 
    } %> 
    </body> 
    </html> 
      

  7.   

    163.com 126.com 21cn.com yahoo.com.cn  tom.com的邮箱都可以发
      

  8.   

    晕!
    星际孤虹给了好大一陀哦。我只要发送mail的一个东东(不是要邮件系统啊),您给我弄了这么一大串。。感谢感谢!有没有精简一点的代码,只要发送mail即可。
      

  9.   

    你的邮件服务器发送需要验证的啊,nanman(南蛮—50万人使用的最强五笔作者) 
    给了解答了。