canglang0 2011-05-07 23:56
浏览 469
已采纳

邮件发送时报553错误

jsp源码:
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="javax.mail.internet.*" %>
<%@ page import="javax.activation.*" %>
<%@ page import="javax.mail.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="com.bwm.db.Conn"%>
<%@ page import="com.bwm.page.Show" %>
<%
request.setCharacterEncoding("GB2312");
Show show=new Show();
Conn con=new Conn();
boolean blnError=true;
boolean blnSend=false;
String strTo ="";
String strUserName=(String)session.getAttribute("name");
String strUse=(String)session.getAttribute("use");
System.out.println("send.jsp第19行。strUserName="+strUserName+",strUse="+strUse);
String strSql="";
if(strUse!=null&&strUse.equals("student")){
strSql="SELECT email FROM tb_student WHERE sname='"+strUserName+"'";
}else if(strUse!=null&&strUse.equals("company")){
strSql="SELECT email FROM tb_company WHERE cname='"+strUserName+"'";
}else {
out.print(show.errorBox("你还没有登录不能发送Email","警告信息"));
return;
}
System.out.println("send.jsp第29行。strSql="+strSql);
ResultSet rs=con.getRs(strSql);
if(rs.next()){
strTo=rs.getString(1);
System.out.println("send.jsp第33行。strTo="+strTo);
}
//send Email
InternetAddress[] address = null;
String strMailserver = "smtp.163.com";
String [] arrstrFrom=request.getParameterValues("from");
String strSubject = request.getParameter("subject");
String strMessage = request.getParameter("message");
System.out.println("send.jsp第41行。strSubject="+strSubject+",strMessage="+strMessage);
if(arrstrFrom.length>0){
int intI=0;
for(intI=0;intI<arrstrFrom.length;intI++){
if(!arrstrFrom[intI].equals("")){
try {
System.out.println("send.jsp第47行。arrstrFrom[intI]="+arrstrFrom[intI]);
// 设定所要用的Mail 服务器和所使用的传输协议
java.util.Properties props = System.getProperties();
props.put("mail.host",strMailserver);
props.put("mail.transport.protocol","smtp");

                            // 产生新的Session 服务
                            javax.mail.Session mailSession = javax.mail.Session.getDefaultInstance(props,null);
                            mailSession.setDebug(false);

                            Message msg = new MimeMessage(mailSession);

                            // 设定传送邮件的发信人
                            msg.setFrom(new InternetAddress(strTo));

                            // 设定传送邮件至收信人的信箱
                            address = InternetAddress.parse(arrstrFrom[intI],false);
                            msg.setRecipients(Message.RecipientType.TO, address);

                            // 设定信中的主题
                            msg.setSubject(strSubject);

                            // 设定送信的时间
                            msg.setSentDate(new java.util.Date());

                            // 设定传送信的MIME Type
                            msg.setText(strMessage);

                            // 送信
                            Transport.send(msg);

                            out.print("邮件已顺利传送到"+arrstrFrom[intI]+" <br>");
                            blnSend=true;
                    }catch (Exception e) {
                            if(blnError)
                                    out.print(show.errorBox(e.getMessage(),"发送失败"));
                            blnError=false;
                            e.printStackTrace();
                    }
            }
    }

}else{
out.print(show.errorBox("请添写完整信息!","错误信息"));
}
if(blnSend){
out.print(show.errorBox("邮件发送成功!","发送信息"));
}else if(blnError&!blnSend){
out.print(show.errorBox("邮件发送失败!","发送信息"));
}
%>

控制台信息:
send.jsp第19行。strUserName=1,strUse=student
send.jsp第29行。strSql=SELECT email FROM tb_student WHERE sname='1'
send.jsp第33行。strTo=canglang0@163.com
send.jsp第41行。strSubject=a,strMessage=a
send.jsp第47行。arrstrFrom[intI]= canglang0@163.com

javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.MessagingException: 553 You are not authorized to send mail, authentication is required

at javax.mail.Transport.send0(Transport.java:218)
at javax.mail.Transport.send(Transport.java:80)
at org.apache.jsp.mail.send_jsp._jspService(send_jsp.java:136)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
  • 写回答

3条回答 默认 最新

  • zzfolin 2011-05-08 00:08
    关注

    javax.mail.SendFailedException: Sending failed;
    nested exception is:
    class javax.mail.MessagingException: 553 You are not authorized to send mail, authentication is required

    身份验证失败,你的设置发送人的账号、密码有问题,还有你的代码怎么写在JSP上面哦??不会建个Class?那么乱。。。

    贴一段我写的JavaMail的Demo:
    [code="java"]
    package com._100fly.javamail;

    import java.util.Properties;

    import javax.mail.Authenticator;
    import javax.mail.Message;
    import javax.mail.MessagingException;
    import javax.mail.PasswordAuthentication;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.Message.RecipientType;
    import javax.mail.internet.AddressException;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;

    public class SencMail {

    /**
     * @param args
     * @throws MessagingException 
     * @throws AddressException 
     * @throws MessagingException 
     */
    public static void main(String[] args) throws AddressException, MessagingException {
        // TODO Auto-generated method stub
        Properties props = new Properties();
    
        //两个属性必须配置
    
        //连哪种服务器
        props.setProperty("mail.transport.protocol", "smtp");
        //设置需要验证(给提供用户名、密码)
        props.setProperty("mail.smtp.auth", "true");
        props.setProperty("mail.host", "smtp.gmail.com");
        Session session = Session.getInstance(props,
    
                //返回验证信息的内部类
                new Authenticator()
                {
    
                    protected PasswordAuthentication getPasswordAuthentication()
                    {
    
                        return new PasswordAuthentication("mengzhongyouni@gmail.com","zeng@4717");
                    }
                }
    
        );
    
        session.setDebug(true);
    
        Message msg = new MimeMessage(session);
        try {
            msg.setFrom(new InternetAddress("hello@gmail.com"));
            msg.setSubject("中文主题");
            msg.setRecipients(RecipientType.TO, InternetAddress.parse("1260128980@qq.com,mengzhongyouni@gmail.com"));
            msg.setContent("<span style='color:red'>我是以HTML代码解析出来的</span>", "text/html;charset=gbk");
    
            //没有指定收件人 会在msg里面去找
            Transport.send(msg);
        } catch (AddressException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (MessagingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
    }
    

    }

    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 您好 这个API接口该怎么弄 网站搭建好了 API也有 现在就不知道该怎么填写API 不知道怎么用
  • ¥88 用uniapp写一个多端的程序,用到高德地图,用高德的JSAPI吗?
  • ¥20 关于#c++#的问题:水果店管理系统
  • ¥30 dbLinq最新版linq sqlite
  • ¥20 对D盘进行分盘之前没有将visual studio2022卸载掉,现在该如何下载回来
  • ¥15 完成虚拟机环境配置,还有安装kettle
  • ¥15 2024年全国大学生数据分析大赛A题:直播带货与电商产品的大数据分析 问题5. 请设计一份优惠券的投放策略,需要考虑优惠券的数量、优惠券的金额、投放时间段和投放商品种类等因素。求具体的python代码
  • ¥15 有人会搭建生鲜配送自营+平台的管理系统吗
  • ¥15 用matlab写代码
  • ¥30 motoradmin系统的多对多配置