javax.mail发送邮件时收件人地址报错

J2EE 码拜 5年前 (2015-04-21) 189次浏览 0个评论
 

求高手指教 这个错误怎么改啊?
代码如下:              String content = code ;
     java.util.Properties props = System.getProperties();
     props.put(“mail.host”, mailSever);
     props.put(“mail.transport.protocol”, “smtp”);
     props.put(“mail.smtp.auth”,”true”);
     MyAuth auth = new MyAuth(userName, passwd);
     auth.getPasswordAuthentication();
     System.out.println(“auth===”+auth);
     javax.mail.Session mailSession = javax.mail.Session.getInstance(props, auth);
     mailSession.setDebug(true);
     MimeMessage msg = new MimeMessage(mailSession);
     msg.setFrom(new InternetAddress( from ));
     InternetAddress to_mail = new InternetAddress(“asdasd@163.com,asddsa@163.com”);
     msg.setRecipient(MimeMessage.RecipientType.TO,to_mail);
     msg.setSubject(subject);
     msg.setRecipients(MimeMessage.RecipientType.CC, this.cc );
     msg.setSentDate(new java.util.Date());
     msg.setText(content);
    
     Transport transport=mailSession.getTransport(“smtp”);
        //连接SMTP服务器
        transport.connect(mailSever, userName, passwd);
        //发送邮件 
        //Transport.send(message,message.getAllRecipients());
        transport.sendMessage(msg,msg.getAllRecipients());
        transport.close();
     //Transport.send(msg);
     System.out.println(” Success !”);  

DEBUG: setDebug: JavaMail version 1.4.2
javax.mail.internet.AddressException: Illegal address in string “asdasd@163.com,asddsa@163.com””””
at javax.mail.internet.InternetAddress.<init>(InternetAddress.java:110)
at cn.com.softvan.eos.bizlet.p17.SendMail.send3(SendMail.java:252)
at cn.com.softvan.eos.bizlet.p17.SendEMail.SendMailToSysAndcc(SendEMail.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.primeton.tp.core.bizservice.state.MethodBizState.invoke(MethodBizState.java:74)
at com.primeton.tp.core.bizservice.ProcessRunner.implement(ProcessRunner.java:135)
at com.primeton.tp.core.bizservice.state.SubProcessBizState.invoke(SubProcessBizState.java:156)
at com.primeton.tp.core.bizservice.ProcessRunner.implement(ProcessRunner.java:135)
at com.primeton.tp.core.bizservice.state.SubProcessBizState.invoke(SubProcessBizState.java:156)
at com.primeton.tp.core.bizservice.ProcessRunner.implement(ProcessRunner.java:135)
at com.primeton.tp.core.bizservice.ProcessCaller.implement_noEJB(ProcessCaller.java:193)
at com.primeton.tp.core.bizservice.ProcessCaller.implement(ProcessCaller.java:87)
at org.apache.jsp.internet.debug.bizlogicDebugger_jsp._jspService(bizlogicDebugger_jsp.java:62)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:72)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.jboss.web.tomcat.security.JBossSecurityMgrRealm.invoke(JBossSecurityMgrRealm.java:275)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)

javax.mail发送邮件时收件人地址报错
应该用分号啊,javax.mail.internet.AddressException: Illegal address in string  明显地址错误
javax.mail发送邮件时收件人地址报错
你得先判断收件人地址对不对,这个具体的我也没有啥办法先判断。所以我记得我以前的处理方式是直接截获SendFailedException异常,就能得到一个错误的地址,然后对这个字符串进行处理,再重新发送。

错误地址的接收方法是: Address[] addrs = e.getInvalidAddresses();

数组如何处理你懂的。

javax.mail发送邮件时收件人地址报错
at javax.mail.internet.InternetAddress.<init>(InternetAddress.java:110)
at cn.com.softvan.eos.bizlet.p17.SendMail.send3(SendMail.java:252)

这里在InternetAddress初始化的时候报的错,还没经由网络发送。
所以同一楼,多邮件格式问题,或者支不支持多邮件连接?很有可能用分号(貌似是一种业界标准来的)。

javax.mail发送邮件时收件人地址报错
80分
InternetAddress to_mail = new InternetAddress(“asdasd@163.com,asddsa@163.com”);
修改为
InternetAddress[] to_mail = new InternetAddress[]{“asdasd@163.com”,”asddsa@163.com”};
javax.mail发送邮件时收件人地址报错
msg.setRecipient(MimeMessage.RecipientType.TO,InternetAddress.parse(“asdasd@163.com”,”asddsa@163.com”));

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明javax.mail发送邮件时收件人地址报错
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!